diff --git a/.gitignore b/.gitignore index f2d219a41c5b6082a40a7949b51cb8e4b48fa70e..b13ff3fc1295c41ec909484e61fbd213f13182db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ #for docs and setup.py outputs build/ -tresults/ +tresults*/ # test cache gwinc/test/cache +test/*/*.h5 # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/conftest.py b/conftest.py index 546d97072babe34cfebfa48731308e43f13f5c65..8e8382807413a6a37a360f06ed241d20cc4cd5da 100644 --- a/conftest.py +++ b/conftest.py @@ -40,6 +40,14 @@ def pytest_addoption(parser): help="Do not preclear tpaths", ) + parser.addoption( + "--generate", + action="store_true", + default=False, + dest="generate", + help="Generate test data", + ) + @pytest.fixture def plot(request): @@ -270,3 +278,24 @@ def relfile_test(_file_, request, pre = None, post = None, fname = None): else: return relfile(_file_, testname, fname = fname) + +def pytest_collection_modifyitems(config, items): + """ + Modifies tests to be selectively skipped with command line options + + https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option + """ + # run tests marked as generate if and only if --generate is given + # skip all others in this case + if config.getoption('--generate'): + skip = pytest.mark.skip( + reason='only running tests that generate data') + for item in items: + if 'generate' not in item.keywords: + item.add_marker(skip) + else: + skip = pytest.mark.skip( + reason='generates test data: needs --generate to run') + for item in items: + if 'generate' in item.keywords: + item.add_marker(skip) diff --git a/pytest.ini b/pytest.ini index e5feb65017a11650752b9e48d264a65f7e7181cc..4818fd8911dafc1e599c9e5e3e3e2107c167be22 100644 --- a/pytest.ini +++ b/pytest.ini @@ -9,6 +9,7 @@ markers = fast: marks tests as being fast, usually it does not make plots logic: is a test of the code logic noise: is a test of the noise curves + generate: marks a function that generates test data [pytest-watch] ignore = .*