Skip to content

Commit

Permalink
Simplify pytest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ivirshup committed Jul 28, 2023
1 parent 1ba8ad1 commit d39c5d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: micromamba list

- name: Run test
run: pytest --only-gpu --cov --cov-report=xml --cov-context=test -n 4
run: pytest -m gpu --cov --cov-report=xml --cov-context=test -n 4

- uses: codecov/codecov-action@v3
with:
Expand Down
24 changes: 7 additions & 17 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--only-gpu",
action="store_true",
default=False,
help="Only run GPU tests.",
)
def pytest_itemcollected(item):
# Defniing behavior of pytest.mark.gpu
from importlib.util import find_spec


def pytest_runtest_setup(item):
gpu = len([mark for mark in item.iter_markers(name="gpu")]) > 0

if not gpu: # Skip non gpu tests on gpu CI
if item.config.getoption("--only-gpu"):
pytest.skip("Only running GPU tests.")
else: # Skip GPU tests if cupy not installed
from importlib.util import find_spec

if not find_spec("cupy"):
pytest.skip("Cupy not installed.")
if gpu:
item.add_marker(
pytest.mark.skipif(not find_spec("cupy"), reason="Cupy not installed.")
)

0 comments on commit d39c5d3

Please sign in to comment.