Skip to content

Commit

Permalink
Add support for running pytest in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
James Bensley committed Nov 11, 2024
1 parent bf796f7 commit d8f231c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dnas/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mypy==1.6.1
oauthlib==3.2.2
packaging==23.2
pyparsing==3.0.9
pytest==7.4.2
pytest==8.3.3
pytest-xdist==3.6.1
redis==4.4.4
requests==2.32.0
requests-oauthlib==1.3.1
Expand Down
8 changes: 8 additions & 0 deletions dnas/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
import sys
import unittest

import pytest

sys.path.append(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
)
from dnas.config import config
from dnas.git import git


@pytest.mark.sequential_tests
class test_git(unittest.TestCase):
"""
The git tests must be run sequential, using a pytest marker to exclude
from parallel tests.
"""

cfg = config()
g = git()
test_filename = "abc123"
Expand Down
15 changes: 12 additions & 3 deletions dnas/tests/test_mrt_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
import unittest

import pytest

sys.path.append(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")
)
Expand All @@ -14,7 +16,14 @@
from dnas.mrt_stats import mrt_stats


@pytest.mark.sequential_tests
class test_mrt_stats(unittest.TestCase):
"""
Run these tests sequentially. When run in parallel,
setUp() doesn't finish before the unit tests run so they fail.
Probably something that can be fixed in the future.
"""

def setUp(self: "test_mrt_stats") -> None:
"""
Copy the test files to the location they would be in,
Expand Down Expand Up @@ -122,15 +131,15 @@ def setUp(self: "test_mrt_stats") -> None:
"RRC1/",
self.upd_5_fn + ".json",
)
if not os.path.isfile(self.upd_3_json):
if not os.path.isfile(self.upd_5_json):
raise Exception(
f"Test stats JSON dump is not found: {self.upd_3_json}"
f"Test stats JSON dump is not found: {self.upd_5_json}"
)

self.upd_1_test = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"RRC23/",
"rrc23.updates.20220421.0200.gz.test",
f"{self.upd_1_fn}.test",
)

def test_init(self: "test_mrt_stats") -> None:
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ deps = {[testenv]deps}
passenv = *
changedir = {toxinidir}
commands =
pytest -vvvv dnas/tests/ {posargs}
pytest -vvvv -n 4 -m "not sequential_tests" dnas/tests/ {posargs}
pytest -vvvv -m "sequential_tests" dnas/tests/ {posargs}

[testenv:shellcheck]
skip_install=true
Expand Down

0 comments on commit d8f231c

Please sign in to comment.