Skip to content

Commit f2c44e3

Browse files
bottlerfacebook-github-bot
authored andcommitted
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
1 parent a9b0d50 commit f2c44e3

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

tests/test_build.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,19 @@ def test_no_import_cycles(self):
118118
# Check each module of pytorch3d imports cleanly,
119119
# which may fail if there are import cycles.
120120

121-
# First check the setup of the test. If any of pytorch3d
122-
# was already imported the test would be pointless.
123-
for module in sys.modules:
124-
self.assertFalse(module.startswith("pytorch3d"), module)
125-
126-
root_dir = get_pytorch3d_dir() / "pytorch3d"
127-
for module_file in root_dir.glob("**/*.py"):
128-
if module_file.stem == "__init__":
129-
continue
130-
relative_module = str(module_file.relative_to(root_dir))[:-3]
131-
module = "pytorch3d." + relative_module.replace("/", ".")
132-
with self.subTest(name=module):
133-
with unittest.mock.patch.dict(sys.modules):
134-
importlib.import_module(module)
121+
with unittest.mock.patch.dict(sys.modules):
122+
for module in list(sys.modules):
123+
# If any of pytorch3d is already imported,
124+
# the test would be pointless.
125+
if module.startswith("pytorch3d"):
126+
sys.modules.pop(module, None)
127+
128+
root_dir = get_pytorch3d_dir() / "pytorch3d"
129+
for module_file in root_dir.glob("**/*.py"):
130+
if module_file.stem in ("__init__", "plotly_vis"):
131+
continue
132+
relative_module = str(module_file.relative_to(root_dir))[:-3]
133+
module = "pytorch3d." + relative_module.replace("/", ".")
134+
with self.subTest(name=module):
135+
with unittest.mock.patch.dict(sys.modules):
136+
importlib.import_module(module)

0 commit comments

Comments
 (0)