diff --git a/_unittest/conftest.py b/_unittest/conftest.py index afbf23fabd4..0c1994057fb 100644 --- a/_unittest/conftest.py +++ b/_unittest/conftest.py @@ -27,6 +27,7 @@ import tempfile import time +import matplotlib import pytest from pyaedt.generic.settings import settings @@ -219,3 +220,9 @@ def _method(project_name=None, subfolder=""): ) return _method + + +@pytest.fixture(autouse=True) +def matplotlib_use_agg(): + """Configure Matplotlib to use 'Agg' backend for all tests.""" + matplotlib.use("Agg") diff --git a/_unittest/test_02_2D_modeler.py b/_unittest/test_02_2D_modeler.py index f4985110b52..bfdc97894f0 100644 --- a/_unittest/test_02_2D_modeler.py +++ b/_unittest/test_02_2D_modeler.py @@ -167,15 +167,14 @@ def test_09_plot(self): position=[0, 0, 0], start_point=[0, 0, 2], num_sides=3, name="MyPolygon", material="Copper" ) obj = self.aedtapp.plot( - show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), show_bounding=True, show_grid=True, ) assert os.path.exists(obj.image_file) - obj2 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy") + obj2 = self.aedtapp.plot(export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy") assert os.path.exists(obj2.image_file) - obj3 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy1") + obj3 = self.aedtapp.plot(export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy1") assert filecmp.cmp(obj.image_file, obj3.image_file) def test_10_edit_menu_commands(self): diff --git a/_unittest/test_12_1_PostProcessing.py b/_unittest/test_12_1_PostProcessing.py index addd18ff579..33eb6408a51 100644 --- a/_unittest/test_12_1_PostProcessing.py +++ b/_unittest/test_12_1_PostProcessing.py @@ -112,7 +112,6 @@ def test_01_Animate_plt(self): intrinsics={"Freq": "5GHz", "Phase": "0deg"}, variation_variable="Phase", variations=phases, - show=False, export_gif=True, export_path=self.local_scratch.path, ) @@ -127,7 +126,6 @@ def test_01_Animate_plt(self): variations=phases, project_path="", export_gif=False, - show=False, ) model_gif2.gif_file = os.path.join(self.aedtapp.working_directory, "test2.gif") model_gif2.camera_position = [0, 50, 200] @@ -514,7 +512,6 @@ def test_14_Field_Ploton_cutplanedesignname(self): image_format="jpg", view="xy", plot_label=plot1.name + " label", - show=False, ) assert os.path.exists(plot_obj.image_file) os.unlink(plot_obj.image_file) @@ -539,7 +536,6 @@ def test_14_Field_Ploton_cutplanedesignname(self): image_format="jpg", view="xy", plot_label=plot1.name + " label", - show=False, file_format="aedtplt", ) assert os.path.exists(plot_obj.image_file) @@ -566,7 +562,6 @@ def test_14B_Field_Ploton_Vector(self): intrinsics=intrinsic, mesh_on_fields=False, view="isometric", - show=False, export_path=self.local_scratch.path, image_format="jpg", ) @@ -574,12 +569,10 @@ def test_14B_Field_Ploton_Vector(self): @pytest.mark.skipif(is_linux or sys.version_info < (3, 8), reason="Not running in ironpython") def test_15_export_plot(self): - obj = self.aedtapp.post.plot_model_obj( - show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg") - ) + obj = self.aedtapp.post.plot_model_obj(export_path=os.path.join(self.local_scratch.path, "image.jpg")) assert os.path.exists(obj.image_file) obj2 = self.aedtapp.post.plot_model_obj( - show=False, export_path=os.path.join(self.local_scratch.path, "image2.jpg"), plot_as_separate_objects=False + export_path=os.path.join(self.local_scratch.path, "image2.jpg"), plot_as_separate_objects=False ) assert os.path.exists(obj2.image_file) diff --git a/_unittest/test_12_PostProcessing.py b/_unittest/test_12_PostProcessing.py index 03f2ba5bd0b..647651fb1cf 100644 --- a/_unittest/test_12_PostProcessing.py +++ b/_unittest/test_12_PostProcessing.py @@ -417,7 +417,7 @@ def test_55_time_plot(self, sbr_test): ) assert os.path.exists(frames_list) sbr_test.post.plot_scene( - frames_list, os.path.join(sbr_test.working_directory, "animation.gif"), norm_index=5, dy_rng=35, show=False + frames_list, os.path.join(sbr_test.working_directory, "animation.gif"), norm_index=5, dy_rng=35 ) assert os.path.exists(os.path.join(sbr_test.working_directory, "animation.gif")) sbr_test.post.plot_scene( @@ -425,7 +425,6 @@ def test_55_time_plot(self, sbr_test): os.path.join(sbr_test.working_directory, "animation2.gif"), norm_index=5, dy_rng=35, - show=False, convert_fields_in_db=True, log_multiplier=20.0, ) @@ -616,14 +615,13 @@ def test_70_far_field_data(self): ffdata.polar_plot_3d_pyvista( quantity="RealizedGain", image_path=img4, - show=False, background=[255, 0, 0], show_geometry=False, convert_to_db=True, ) assert os.path.exists(img4) data_pyvista = ffdata.polar_plot_3d_pyvista( - quantity="RealizedGain", show=False, background=[255, 0, 0], show_geometry=False, convert_to_db=True + quantity="RealizedGain", background=[255, 0, 0], show_geometry=False, convert_to_db=True ) assert isinstance(data_pyvista, Plotter) @@ -639,7 +637,6 @@ def test_71_antenna_plot(self, field_test): title="Contour at {}Hz".format(ffdata.frequency), image_path=os.path.join(self.local_scratch.path, "contour.jpg"), convert_to_db=True, - show=False, ) assert os.path.exists(os.path.join(self.local_scratch.path, "contour.jpg")) @@ -669,13 +666,12 @@ def test_71_antenna_plot(self, field_test): ffdata.polar_plot_3d_pyvista( quantity="RealizedGain", image_path=os.path.join(self.local_scratch.path, "3d2.jpg"), - show=False, convert_to_db=True, ) assert os.path.exists(os.path.join(self.local_scratch.path, "3d2.jpg")) try: - p = ffdata.polar_plot_3d_pyvista(quantity="RealizedGain", show=False, convert_to_db=True) + p = ffdata.polar_plot_3d_pyvista(quantity="RealizedGain", convert_to_db=True) assert isinstance(p, object) except Exception: assert True @@ -689,7 +685,6 @@ def test_72_antenna_plot(self, array_test): title="Contour at {}Hz".format(ffdata.frequency), image_path=os.path.join(self.local_scratch.path, "contour.jpg"), convert_to_db=True, - show=False, ) assert os.path.exists(os.path.join(self.local_scratch.path, "contour.jpg")) @@ -699,7 +694,6 @@ def test_72_antenna_plot(self, array_test): secondary_sweep_value=[-180, -75, 75], title="Azimuth at {}Hz".format(ffdata.frequency), image_path=os.path.join(self.local_scratch.path, "2d1.jpg"), - show=False, ) assert os.path.exists(os.path.join(self.local_scratch.path, "2d1.jpg")) ffdata.plot_2d_cut( @@ -708,7 +702,6 @@ def test_72_antenna_plot(self, array_test): secondary_sweep_value=30, title="Azimuth at {}Hz".format(ffdata.frequency), image_path=os.path.join(self.local_scratch.path, "2d2.jpg"), - show=False, ) assert os.path.exists(os.path.join(self.local_scratch.path, "2d2.jpg")) @@ -721,7 +714,6 @@ def test_72_antenna_plot(self, array_test): ffdata.polar_plot_3d_pyvista( quantity="RealizedGain", image_path=os.path.join(self.local_scratch.path, "3d2.jpg"), - show=False, convert_to_db=True, ) assert os.path.exists(os.path.join(self.local_scratch.path, "3d2.jpg")) @@ -731,7 +723,6 @@ def test_72_antenna_plot(self, array_test): title="Contour at {}Hz".format(ffdata1.frequency), image_path=os.path.join(self.local_scratch.path, "contour1.jpg"), convert_to_db=True, - show=False, ) assert os.path.exists(os.path.join(self.local_scratch.path, "contour1.jpg")) diff --git a/_unittest_solvers/conftest.py b/_unittest_solvers/conftest.py index 6d581605884..5a0207899e2 100644 --- a/_unittest_solvers/conftest.py +++ b/_unittest_solvers/conftest.py @@ -18,6 +18,7 @@ """ import json +import matplotlib import os import shutil import sys @@ -206,3 +207,8 @@ def _method(project_name=None, subfolder=""): ) return _method + +@pytest.fixture(autouse=True) +def matplotlib_use_agg(): + """Configure Matplotlib to use 'Agg' backend for all tests.""" + matplotlib.use("Agg") diff --git a/doc/source/conf.py b/doc/source/conf.py index 4e3a6246035..801d2339e39 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -277,12 +277,17 @@ def setup(app): # Must be less than or equal to the XVFB window size pyvista.global_theme["window_size"] = np.array([1024, 768]) - # suppress annoying matplotlib bug + # Suppress annoying matplotlib bug warnings.filterwarnings( "ignore", category=UserWarning, message="Matplotlib is currently using agg, which is a non-GUI backend, so it cannot show the figure.", ) + warnings.filterwarnings( + "ignore", + category=UserWarning, + message="FigureCanvasAgg is non-interactive, and thus cannot be shown", + ) extensions.append("sphinx_gallery.gen_gallery") sphinx_gallery_conf = {