Skip to content

Commit 671dfd0

Browse files
author
David Rickett
committed
Add pytest-xdist to speed up tests.
1 parent c613442 commit 671dfd0

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.venv
22
**/__pycache__
33
**/.pytest_cache
4-
.coverage
4+
.coverage*
55
**/output/
66
**/*.xml
77
**/*.fasta

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extra-dependencies = [
8080
"pytest-cov",
8181
"pytest-html",
8282
"pytest-mock",
83+
"pytest-xdist",
8384
]
8485

8586
[tool.hatch.envs.dev]
@@ -89,6 +90,7 @@ extra-dependencies = [
8990
"pytest-cov",
9091
"pytest-html",
9192
"pytest-mock",
93+
"pytest-xdist",
9294
"black",
9395
"mypy-extensions"
9496
]
@@ -105,7 +107,7 @@ python = ["38", "39", "310", "311"]
105107

106108
[tool.pytest.ini_options]
107109
minversion = "6.0"
108-
addopts = "-ra --cov --cov-report xml --strict-markers -m 'not slow'"
110+
addopts = "-ra -n 4 --cov --cov-report xml --strict-markers -m 'not slow'"
109111
testpaths = [
110112
"tests",
111113
]

tests/easyhla_test.py

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,6 @@ def test_check_length_hla_type_a(
157157
letter=easyhla.letter, seq=sequence, name=name
158158
)
159159

160-
@pytest.mark.integration
161-
@pytest.mark.slow
162-
def test_run(self, easyhla: EasyHLA):
163-
"""
164-
Integration test, assert that pyEasyHLA produces an identical output to
165-
the original Ruby output.
166-
"""
167-
input_file = os.path.dirname(__file__) + "/input/hla-a-seqs.fasta"
168-
ref_output_file = os.path.dirname(__file__) + "/output/hla-a-output.csv"
169-
output_file = os.path.dirname(__file__) + "/output/hla-a-test.csv"
170-
171-
easyhla.run(
172-
easyhla.letter,
173-
input_file,
174-
output_file,
175-
0,
176-
)
177-
178-
compare_ref_vs_test(
179-
easyhla=easyhla,
180-
reference_output_file=ref_output_file,
181-
output_file=output_file,
182-
)
183-
184160
@pytest.mark.parametrize(
185161
"best_matches, exp_ambig, exp_alleles",
186162
[
@@ -1129,3 +1105,60 @@ def test_alleles_clean(
11291105
result = easyhla.get_clean_alleles(all_alleles=alleles)
11301106

11311107
assert result == exp_result
1108+
1109+
@pytest.mark.integration
1110+
@pytest.mark.slow
1111+
def test_run(self, easyhla: EasyHLA):
1112+
"""
1113+
Integration test, assert that pyEasyHLA produces an identical output to
1114+
the original Ruby output.
1115+
"""
1116+
1117+
input_file = (
1118+
os.path.dirname(__file__)
1119+
+ f"/input/hla-{easyhla.letter.lower()}-seqs.fasta"
1120+
)
1121+
ref_output_file = (
1122+
os.path.dirname(__file__)
1123+
+ f"/output/hla-{easyhla.letter.lower()}-output-ref.csv"
1124+
)
1125+
output_file = (
1126+
os.path.dirname(__file__) + f"/output/hla-{easyhla.letter.lower()}-test.csv"
1127+
)
1128+
1129+
if not os.path.exists(input_file):
1130+
pytest.skip("Input sequence does not exist!")
1131+
if not os.path.exists(ref_output_file):
1132+
pytest.skip("Reference output does not exist!")
1133+
1134+
start_time = datetime.now()
1135+
print(f"Test started at {start_time.isoformat()}")
1136+
1137+
easyhla.run(
1138+
easyhla.letter,
1139+
input_file,
1140+
output_file,
1141+
0,
1142+
)
1143+
1144+
end_time = datetime.now()
1145+
1146+
print(f"Interpretation ended at {end_time.isoformat()}")
1147+
1148+
compare_ref_vs_test(
1149+
easyhla=easyhla,
1150+
reference_output_file=ref_output_file,
1151+
output_file=output_file,
1152+
)
1153+
1154+
end_compare_time = datetime.now()
1155+
1156+
print(f"Test ended at {end_compare_time.isoformat()}")
1157+
1158+
print(f"Time elapsed: {(end_compare_time-start_time).total_seconds()}")
1159+
print(
1160+
f"Time elapsed for interpretation: {(end_time-start_time).total_seconds()}"
1161+
)
1162+
print(
1163+
f"Time elapsed for output comparison: {(end_compare_time-end_time).total_seconds()}"
1164+
)

0 commit comments

Comments
 (0)