From 77b94a40babfea160130c70160dfdf60356b4f16 Mon Sep 17 00:00:00 2001 From: Oliver Holworthy Date: Tue, 4 Jul 2023 11:04:35 +0100 Subject: [PATCH] Add Pytest Markers Configuration (#1849) * Add pytest.ini with markers specified * Update conftest with automatic markers based on test path --------- Co-authored-by: Karl Higley --- pytest.ini | 10 ++++++++++ tests/conftest.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000000..70cd77bbaf --- /dev/null +++ b/pytest.ini @@ -0,0 +1,10 @@ +[pytest] +markers = + unit: mark as unit test + examples: mark as example + ops: mark as tesing operators + loader: mark as testing the dataloader + tensorflow: mark as using tensorflow + torch: mark as using torch + singlegpu: mark as testing single GPU + multigpu: mark as testing multi-GPU diff --git a/tests/conftest.py b/tests/conftest.py index b8ed0a32f6..f1e05da2f5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -374,6 +374,29 @@ def report(request): return request.config.getoption("--report") +def pytest_collection_modifyitems(items): + for item in items: + path = item.location[0] + + if "/unit/" in path: + item.add_marker(getattr(pytest.mark, "unit")) + + if "/loader/" in path: + item.add_marker(getattr(pytest.mark, "loader")) + + if "/examples/" in path: + item.add_marker(getattr(pytest.mark, "examples")) + + if "/ops/" in path: + item.add_marker(getattr(pytest.mark, "ops")) + + if "test_tf_" in path: + item.add_marker(getattr(pytest.mark, "tensorflow")) + + if "test_torch_" in path: + item.add_marker(getattr(pytest.mark, "torch")) + + @pytest.fixture(scope="function", autouse=True) def cleanup_dataloader(): """After each test runs. Call .stop() on any dataloaders created during the test.