Skip to content

Commit 3e66fe5

Browse files
authored
Prevent test discovery from loading models (#915)
Since we started putting models in tests/models, unittest (which geltest uses also for this) test discovery will go and recursively import models that are sitting around between test runs. This is rough as some/all of them are about to be blown away and regenerated. If we just switched from some branch making interesting changes, the imports might fail. unittest has a `load_tests` protocol that we can use to take charge of our own test loading for a package... and then not do any.
1 parent 436af50 commit 3e66fe5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gel/_internal/_testbase/_models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,13 @@ async def set_up_class_once(cls, ui: UI) -> None:
358358
models_dir = test_dir / "models"
359359
models_dir.mkdir(exist_ok=True)
360360
# Make sure the base "models" directory has an __init__.py
361-
(models_dir / "__init__.py").touch()
361+
(models_dir / "__init__.py").write_text(
362+
textwrap.dedent('''\
363+
# Prevent unittest from recursing into the models
364+
def load_tests(*args, **kwargs):
365+
return None
366+
''')
367+
)
362368
# and py.typed
363369
(models_dir / "py.typed").touch()
364370

0 commit comments

Comments
 (0)