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