diff options
| author | 2021-12-03 14:15:14 +0100 | |
|---|---|---|
| committer | 2021-12-03 14:15:51 +0100 | |
| commit | b062e0f2abc189f352e019bac6854f469e9dfc8c (patch) | |
| tree | 95a7a72cf56061278297f6326c8e3f9519432d53 /conftest.py | |
| parent | f3c3fa9b94bc61b90a029bb74c98215b45c5be15 (diff) | |
| download | 2021-b062e0f2abc189f352e019bac6854f469e9dfc8c.tar.gz 2021-b062e0f2abc189f352e019bac6854f469e9dfc8c.tar.bz2 2021-b062e0f2abc189f352e019bac6854f469e9dfc8c.zip | |
Added tests
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 | ) | ||
