diff options
Diffstat (limited to 'conftest.py')
| -rw-r--r-- | conftest.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..3bae1e2 --- /dev/null +++ b/conftest.py | |||
| @@ -0,0 +1,35 @@ | |||
| 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 | ||
| 16 | in walk_packages([dir_path]) | ||
| 17 | if package.name.startswith('day') | ||
| 18 | ] | ||
| 19 | |||
| 20 | assignments = [ | ||
| 21 | (getattr(package, f'Assignment{day(part)}'), 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) | ||
| 31 | in assignments | ||
| 32 | if Assignment is not None | ||
| 33 | ], | ||
| 34 | ids=lambda assignment: str(assignment) | ||
| 35 | ) | ||
