diff --git a/src/ifcopenshell-python/test/conftest.py b/src/ifcopenshell-python/test/conftest.py new file mode 100644 index 0000000000..2284b9ee79 --- /dev/null +++ b/src/ifcopenshell-python/test/conftest.py @@ -0,0 +1,7 @@ +def pytest_addoption(parser): + parser.addoption( + "--rule", + action="store", + default=None, + help="Only run test_rules.py fixtures whose filename contains this substring.", + ) diff --git a/src/ifcopenshell-python/test/test_rules.py b/src/ifcopenshell-python/test/test_rules.py index ae981abf00..347d0320d8 100644 --- a/src/ifcopenshell-python/test/test_rules.py +++ b/src/ifcopenshell-python/test/test_rules.py @@ -1,6 +1,5 @@ import glob import os -import sys import pytest import tabulate @@ -9,14 +8,18 @@ import ifcopenshell.express.rule_executor import ifcopenshell.validate -@pytest.mark.parametrize( - "filename", - [ +def pytest_generate_tests(metafunc): + if "filename" not in metafunc.fixturenames: + return + rule = metafunc.config.getoption("--rule") + filenames = [ fn for fn in glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/rules/*.ifc")) - if len(sys.argv) < 2 or sys.argv[1] in os.path.basename(fn) - ], -) + if not rule or rule in os.path.basename(fn) + ] + metafunc.parametrize("filename", filenames, ids=[os.path.basename(fn) for fn in filenames]) + + def test_file(filename): base = os.path.basename(filename) file = ifcopenshell.open(filename)