diff options
Diffstat (limited to 'conftest.py')
| -rw-r--r-- | conftest.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..1c0a8e4 --- /dev/null +++ b/conftest.py | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | import importlib | ||
| 3 | import os | ||
| 4 | from pkgutil import walk_packages | ||
| 5 | |||
| 6 | from _pytest.python import Metafunc | ||
| 7 | |||
| 8 | from aoc.__main__ import day | ||
| 9 | |||
| 10 | dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
| 11 | |||
| 12 | |||
| 13 | def pytest_generate_tests(metafunc: Metafunc): | ||
| 14 | if "assignment" in metafunc.fixturenames: | ||
| 15 | packages = [ | ||
| 16 | importlib.import_module(package.name) | ||
| 17 | for package in walk_packages([dir_path]) | ||
| 18 | ] | ||
| 19 | |||
| 20 | assignments = [ | ||
| 21 | (getattr(package, f"Assignment{day(part)}", None), package) | ||
| 22 | for package in packages | ||
| 23 | for part in ["1", "2"] | ||
| 24 | ] | ||
| 25 | |||
| 26 | metafunc.parametrize( | ||
| 27 | argnames=f"assignment", | ||
| 28 | argvalues=[ | ||
| 29 | Assignment(path=package.__path__[0]) | ||
| 30 | for (Assignment, package) in assignments | ||
| 31 | if Assignment is not None | ||
| 32 | and hasattr(package, "__path__") | ||
| 33 | and Assignment.example_result != NotImplemented | ||
| 34 | ], | ||
| 35 | ids=lambda assignment: str(assignment), | ||
| 36 | ) | ||
