From f2c44e3540d1f62713d2610360be4b0c3e39e129 Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Thu, 2 Sep 2021 08:38:10 -0700 Subject: [PATCH] update test_build for robustness Summary: Change cyclic deps test to be independent of test discovery order. Also let it work without plotly. Reviewed By: nikhilaravi Differential Revision: D30669614 fbshipit-source-id: 2eadf3f8b56b6096c5466ce53b4f8ac6df27b964 --- tests/test_build.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/test_build.py b/tests/test_build.py index f74ca23c..de252d28 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -118,17 +118,19 @@ class TestBuild(unittest.TestCase): # Check each module of pytorch3d imports cleanly, # which may fail if there are import cycles. - # First check the setup of the test. If any of pytorch3d - # was already imported the test would be pointless. - for module in sys.modules: - self.assertFalse(module.startswith("pytorch3d"), module) + with unittest.mock.patch.dict(sys.modules): + for module in list(sys.modules): + # If any of pytorch3d is already imported, + # the test would be pointless. + if module.startswith("pytorch3d"): + sys.modules.pop(module, None) - root_dir = get_pytorch3d_dir() / "pytorch3d" - for module_file in root_dir.glob("**/*.py"): - if module_file.stem == "__init__": - continue - relative_module = str(module_file.relative_to(root_dir))[:-3] - module = "pytorch3d." + relative_module.replace("/", ".") - with self.subTest(name=module): - with unittest.mock.patch.dict(sys.modules): - importlib.import_module(module) + root_dir = get_pytorch3d_dir() / "pytorch3d" + for module_file in root_dir.glob("**/*.py"): + if module_file.stem in ("__init__", "plotly_vis"): + continue + relative_module = str(module_file.relative_to(root_dir))[:-3] + module = "pytorch3d." + relative_module.replace("/", ".") + with self.subTest(name=module): + with unittest.mock.patch.dict(sys.modules): + importlib.import_module(module)