From f3e15ff7c8c1e573ee0ca6036b6320bc665629e7 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 9 Dec 2021 23:03:58 -0800 Subject: [PATCH] Backport PR #21905: Fix image testing decorator in pytest importlib mode --- lib/matplotlib/testing/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index a38d55fd1dcc..ec8f7c4564ea 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -479,7 +479,7 @@ def _image_directories(func): ``$(pwd)/result_images/test_baz``. The result directory is created if it doesn't exist. """ - module_path = Path(sys.modules[func.__module__].__file__) + module_path = Path(inspect.getfile(func)) baseline_dir = module_path.parent / "baseline_images" / module_path.stem result_dir = Path().resolve() / "result_images" / module_path.stem result_dir.mkdir(parents=True, exist_ok=True)