Skip to content

Commit 8a49a65

Browse files
authored
Fix pytest_collection_modifyitems to select benchmark tests only (#1874)
* Fix pytest_collection_modifyitems to select benchmark tests only : Signed-off-by: Achal Shah <achals@gmail.com> * use lists instead of sets for iteration order Signed-off-by: Achal Shah <achals@gmail.com>
1 parent e98d65a commit 8a49a65

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

sdk/python/tests/conftest.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import multiprocessing
1515
from datetime import datetime, timedelta
1616
from sys import platform
17+
from typing import List
1718

1819
import pandas as pd
1920
import pytest
21+
from _pytest.nodes import Item
2022

2123
from tests.data.data_creator import create_dataset
2224
from tests.integration.feature_repos.repo_configuration import (
@@ -52,18 +54,27 @@ def pytest_addoption(parser):
5254
)
5355

5456

55-
def pytest_collection_modifyitems(config, items):
57+
def pytest_collection_modifyitems(config, items: List[Item]):
5658
should_run_integration = config.getoption("--integration") is True
5759
should_run_benchmark = config.getoption("--benchmark") is True
58-
skip_integration = pytest.mark.skip(
59-
reason="not running tests with external dependencies"
60-
)
61-
skip_benchmark = pytest.mark.skip(reason="not running benchmarks")
62-
for item in items:
63-
if "integration" in item.keywords and not should_run_integration:
64-
item.add_marker(skip_integration)
65-
if "benchmark" in item.keywords and not should_run_benchmark:
66-
item.add_marker(skip_benchmark)
60+
61+
integration_tests = [t for t in items if "integration" in t.keywords]
62+
if not should_run_integration:
63+
for t in integration_tests:
64+
items.remove(t)
65+
else:
66+
items.clear()
67+
for t in integration_tests:
68+
items.append(t)
69+
70+
benchmark_tests = [t for t in items if "benchmark" in t.keywords]
71+
if not should_run_benchmark:
72+
for t in benchmark_tests:
73+
items.remove(t)
74+
else:
75+
items.clear()
76+
for t in benchmark_tests:
77+
items.append(t)
6778

6879

6980
@pytest.fixture

0 commit comments

Comments
 (0)