Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 64 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,78 @@
import shutil
from datetime import datetime

import pytest
from _pytest.config import Config, argparsing
from _pytest.python import Function

SLOW_TEST_DAY = "Sunday"


def pytest_addoption(parser: argparsing.Parser) -> None:
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
parser.addoption(
"--slurm-project",
type=str,
default="proj_simscience",
help="SLURM project for cluster tests (default: proj_simscience)",
)


def pytest_configure(config: Config) -> None:
config.addinivalue_line("markers", "slow: mark test as slow to run")
config.addinivalue_line(
"markers", "cluster: mark test as requiring a SLURM cluster environment"
)


def pytest_collection_modifyitems(config: Config, items: list[Function]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems to be duplicated across many repos. Is it possible to move it into VTU?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently so!

if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
if not config.getoption("--runslow"):
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)

if not is_on_slurm():
skip_cluster = pytest.mark.skip(reason="not running on SLURM cluster")
for item in items:
if "cluster" in item.keywords:
item.add_marker(skip_cluster)

# E2E tests (cluster + slow) also require it to be the slow test day
if not is_slow_test_day():
skip_e2e = pytest.mark.skip(reason="not the designated slow test day for e2e tests")
for item in items:
if "weekly" in item.keywords:
item.add_marker(skip_e2e)


def is_on_slurm() -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a pytest plugin in VTU now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it actually is not, but I think it is fair to say that it should be.

"""Returns True if the current environment is a SLURM cluster."""
return shutil.which("sbatch") is not None


def is_slow_test_day(slow_test_day: str = SLOW_TEST_DAY) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should definitely be a plugin.

"""Determine if today is the day to run slow/weekly tests.

Parameters
----------
slow_test_day
The day to run the weekly tests on. Acceptable values are "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", or "Sunday".
Default is "Sunday".

Notes
-----
There is some risk that a test will be inadvertently skipped if there is a
significant delay between when a pipeline is kicked off and when the test
itself is run.
"""
return [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
][datetime.today().weekday()] == slow_test_day
4 changes: 4 additions & 0 deletions tests/psimulate/data/e2e_branches.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Minimal branch configuration for E2E testing.
# 2 draws x 2 seeds x 1 branch (empty) = 4 total jobs.
input_draw_count: 2
random_seed_count: 2
22 changes: 22 additions & 0 deletions tests/psimulate/data/e2e_model_spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Minimal vivarium model specification for E2E testing.
# Runs 2 time steps with 10 simulants -- completes in seconds.
# No components, no data artifact, no results observers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we need observers to do some sorts of E2E tests - e.g. to test that we write results to disk properly?

components:
vivarium.examples.disease_model:
population:
- BasePopulation()
configuration:
time:
start:
year: 2025
month: 1
day: 1
end:
year: 2025
month: 1
day: 15
step_size: 7 # days
population:
population_size: 10
randomness:
key_columns: []
Loading