Skip to content

Commit d175847

Browse files
authored
Merge pull request #333 from OpenFreeEnergy/slow-tests
Add pytest filter for slow tests
2 parents 52dba26 + 8835a9d commit d175847

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

.github/workflows/ci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ jobs:
6363
micromamba list
6464
6565
- name: "Run tests"
66+
env:
67+
# Set the OFE_SLOW_TESTS to True if running a Cron job
68+
OFE_SLOW_TESTS: ${{ fromJSON('{"false":"false","true":"true"}')[github.event_name == 'schedule'] }}
6669
run: |
6770
pytest -n auto -v --cov=openfe --cov=openfecli --cov-report=xml
6871

.github/workflows/mypy.yaml

+10-9
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323

24-
- uses: conda-incubator/setup-miniconda@v2
24+
- name: Setup Micromamba
25+
uses: mamba-org/provision-with-micromamba@main
2526
with:
26-
auto-update-conda: true
27-
use-mamba: true
28-
python-version: 3.9
29-
miniforge-variant: Mambaforge
30-
environment-file: environment.yml
31-
activate-environment: openfe
27+
environment-file: environment.yml
28+
environment-name: openfe
29+
cache-env: true
30+
cache-downloads: true
31+
extra-specs: |
32+
python==3.9
3233
3334
- name: "Install steps"
3435
run: |
@@ -37,8 +38,8 @@ jobs:
3738
3839
- name: "Environment Information"
3940
run: |
40-
mamba info -a
41-
mamba list
41+
micromamba info
42+
micromamba list
4243
4344
- name: "Lint with mypy"
4445
run: mypy

.github/workflows/package-tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040

4141
- name: "run tests"
4242
working-directory: ./dist
43+
env:
44+
OFE_SLOW_TESTS: "true"
4345
run: |
4446
pytest -n auto -v --pyargs openfe.tests
4547
pytest -n auto -v --pyargs openfecli.tests

openfe/protocols/openmm_rfe/equil_rfe_methods.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,10 @@ def run(self, dry=False, verbose=True, basepath=None) -> dict[str, Any]:
436436
smirnoff_stateB.generator)
437437

438438
# 3. Model state A
439+
# Note: protein dry run tests are part of the slow tests and don't show
440+
# up in coverage reports
439441
stateA_ligand_topology = stateA_openff_ligand.to_topology().to_openmm()
440-
if 'protein' in stateA.components:
442+
if 'protein' in stateA.components: # pragma: no-cover
441443
pdbfile: gufe.ProteinComponent = stateA['protein']
442444
stateA_modeller = app.Modeller(pdbfile.to_openmm_topology(),
443445
pdbfile.to_openmm_positions())

openfe/tests/conftest.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This code is part of OpenFE and is licensed under the MIT license.
22
# For details, see https://github.com/OpenFreeEnergy/openfe
3+
import os
34
import importlib
45
import pytest
56
from importlib import resources
@@ -11,12 +12,39 @@
1112
from gufe import SmallMoleculeComponent, LigandAtomMapping
1213

1314

15+
# allow for optional slow tests
16+
# See: https://docs.pytest.org/en/latest/example/simple.html
17+
def pytest_addoption(parser):
18+
parser.addoption(
19+
"--runslow", action="store_true", default=False, help="run slow tests"
20+
)
21+
22+
23+
def pytest_configure(config):
24+
config.addinivalue_line("markers", "slow: mark test as slow to run")
25+
26+
27+
def pytest_collection_modifyitems(config, items):
28+
if (config.getoption("--runslow") or
29+
os.environ['OFE_SLOW_TESTS'].lower() == 'true'):
30+
# --runslow given in cli or OFE_SLOW_TESTS set to True in env vars
31+
# do not skip slow tests
32+
return
33+
msg = ("need --runslow pytest cli option or the environment variable "
34+
"`OFE_SLOW_TESTS` set to `True` to run")
35+
skip_slow = pytest.mark.skip(reason=msg)
36+
for item in items:
37+
if "slow" in item.keywords:
38+
item.add_marker(skip_slow)
39+
40+
1441
def mol_from_smiles(smiles: str) -> Chem.Mol:
1542
m = Chem.MolFromSmiles(smiles)
1643
AllChem.Compute2DCoords(m)
1744

1845
return m
1946

47+
2048
@pytest.fixture(scope='session')
2149
def ethane():
2250
return SmallMoleculeComponent(mol_from_smiles('CC'))

openfe/tests/protocols/test_openmm_equil_rfe_protocols.py

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def test_dry_run_ligand(benzene_system, toluene_system,
133133
assert sampler.is_periodic
134134

135135

136+
@pytest.mark.slow
136137
@pytest.mark.parametrize('method', ['repex', 'sams', 'independent'])
137138
def test_dry_run_complex(benzene_complex_system, toluene_complex_system,
138139
benzene_to_toluene_mapping, method, tmpdir):
@@ -726,6 +727,7 @@ def tyk2_reference_xml():
726727
return ET.fromstring(xmldata)
727728

728729

730+
@pytest.mark.slow
729731
class TestTyk2XmlRegression:
730732
"""Generates Hybrid system XML and performs regression test"""
731733
@staticmethod

0 commit comments

Comments
 (0)