Skip to content

Commit

Permalink
added --run-tests open in pytest (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc committed Mar 7, 2024
2 parents 1194d69 + 32c8796 commit d82757f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ test-verbose:
python -m pytest -vs -o log_cli=true

test-system:
${XVFBRUN} python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov -o log_cli=true --run-system-tests
${XVFBRUN} python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov -o log_cli=true --run-system-tests mantidimaging/gui/test/

test-screenshots:
-mkdir ${TEST_RESULT_DIR}
APPLITOOLS_API_KEY=local APPLITOOLS_IMAGE_DIR=${TEST_RESULT_DIR} ${XVFBRUN} pytest -p no:xdist -p no:randomly -p no:cov mantidimaging/eyes_tests/ -vs
APPLITOOLS_API_KEY=local APPLITOOLS_IMAGE_DIR=${TEST_RESULT_DIR} ${XVFBRUN} pytest -p no:xdist -p no:randomly -p no:cov mantidimaging/eyes_tests/ -vs --run-eyes-tests
@echo "Screenshots writen to" ${TEST_RESULT_DIR}

test-screenshots-win:
-mkdir ${TEST_RESULT_DIR}
${XVFBRUN} pytest -p no:xdist -p no:randomly -p no:cov mantidimaging/eyes_tests/ -vs
${XVFBRUN} pytest -p no:xdist -p no:randomly -p no:cov mantidimaging/eyes_tests/ -vs --run-eyes-tests
@echo "Screenshots writen to" ${TEST_RESULT_DIR}

mypy:
Expand Down
39 changes: 24 additions & 15 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,41 @@
from mantidimaging.core.utility.leak_tracker import leak_tracker


def _test_gui_system_filename_match(basename: str) -> bool:
return "gui_system" in basename and "_test.py" in basename


def pytest_addoption(parser):
parser.addoption("--run-system-tests", action="store_true", default=False, help="Run GUI system tests")
parser.addoption("--run-unit-tests", action="store_true", default=False, help="Run unit tests")
parser.addoption("--run-eyes-tests", action="store_true", default=False, help="Run eyes tests")


def pytest_configure(config):
config.addinivalue_line("markers", "system: GUI system tests")
config.addinivalue_line("markers", "unit: unit tests")
config.addinivalue_line("markers", "eyes: eyes tests")


def pytest_ignore_collect(path, config):
# When running GUI system tests, ignore all other files
if config.getoption("--run-system-tests") and path.isfile() and not _test_gui_system_filename_match(path.basename):
return True
else:
return False
allowed_markers = []
skipped_tests = []


def pytest_collection_modifyitems(config, items):
if not config.getoption("--run-system-tests"):
skip_system = pytest.mark.skip(reason="use --run-system-tests option to run")
for item in items:
if "system" in item.keywords:
item.add_marker(skip_system)
if config.getoption("--run-system-tests"):
allowed_markers.append(pytest.mark.system.mark)
if config.getoption("--run-eyes-tests"):
allowed_markers.append(pytest.mark.eyes.mark)
if config.getoption("--run-unit-tests") or len(allowed_markers) == 0:
allowed_markers.append(pytest.mark.unit.mark)
for item in items:
if "gui_system" in item.nodeid:
item.add_marker(pytest.mark.system)
elif "eyes_test" in item.nodeid:
item.add_marker(pytest.mark.eyes)
else:
item.add_marker(pytest.mark.unit)
if any(mark in allowed_markers for mark in item.own_markers):
pass
else:
item.add_marker(pytest.mark.skip(reason="Test not selected"))
skipped_tests.append(item.nodeid)


# Leak track for tests
Expand Down
1 change: 1 addition & 0 deletions docs/release_notes/next/dev-2082-pytest_separation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#2082: Normal, System, and Screenshot test are now explicitly separated in the Makefile

0 comments on commit d82757f

Please sign in to comment.