Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jobs:
run: git branch -a

- name: Run tests
run: make test
run: make test PYTESTOPTIONS="--skip_vm_tests"

- name: Publish code coverage
uses: codecov/codecov-action@v5
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:
run: git branch -a

- name: Run tests
run: make test
run: make test PYTESTOPTIONS="--skip_vm_tests"

- name: Publish code coverage
uses: codecov/codecov-action@v5
Expand Down Expand Up @@ -311,4 +311,4 @@ jobs:
run: git branch -a

- name: Run tests
run: make test
run: make test PYTESTOPTIONS="--skip_vm_tests"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test: ## Run unit tests
mkdir -p ${TEST_DIR}
cp .coveragerc ${TEST_DIR}
cp setup.cfg ${TEST_DIR}
python -m pytest
python -m pytest $(PYTESTOPTIONS)

test_check_suite: ## run only estimator contract tests in TestAll classes
-rm -rf ${TEST_DIR}
Expand Down
23 changes: 22 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,35 @@ def pytest_addoption(parser):
"""Pytest command line parser options adder."""
parser.addoption(
"--only_changed_modules",
action="store_true",
default=False,
help="test only estimators from modules that have changed compared to main",
)

parser.addoption(
"--run_all_modules",
action="store_true",
default=False,
help="run tests for all modules (override --only_changed_modules)",
)

parser.addoption(
"--skip_vm_tests",
action="store_true",
default=False,
help="skip tests for estimators with 'tests:vm' tag (useful in CI/CD)",
)


def pytest_configure(config):
"""Pytest configuration preamble."""
from skpro.tests import _config

if config.getoption("--only_changed_modules") in [True, "True"]:
# --run_all_modules overrides --only_changed_modules
if config.getoption("--run_all_modules"):
_config.ONLY_CHANGED_MODULES = False
elif config.getoption("--only_changed_modules"):
_config.ONLY_CHANGED_MODULES = True

if config.getoption("--skip_vm_tests"):
_config.SKIP_VM_TESTS = True
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ addopts =
--cov-report xml
--cov-report html
--showlocals
--only_changed_modules True
--only_changed_modules
-n auto
filterwarnings =
ignore::UserWarning
Expand Down
5 changes: 5 additions & 0 deletions skpro/tests/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# default is False, can be set to True by pytest --only_changed_modules True flag
ONLY_CHANGED_MODULES = False

# whether to skip tests for estimators with "tests:vm" tag
# default is False, can be set to True by pytest --skip_vm_tests flag
# useful in CI/CD where VM tests are run separately in dedicated VMs
SKIP_VM_TESTS = False


# list of str, names of estimators to exclude from testing
# WARNING: tests for these estimators will be skipped
Expand Down
15 changes: 11 additions & 4 deletions skpro/tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class for which to determine whether it should be tested
* otherwise, any reasons to run cause the entire list to be run
* otherwise, the list is not run due to "no change"
"""
from skpro.tests._config import ONLY_CHANGED_MODULES
from skpro.tests._config import ONLY_CHANGED_MODULES, SKIP_VM_TESTS

def _return(run, reason):
if return_reason:
Expand Down Expand Up @@ -144,7 +144,9 @@ def _return(run, reason):

# now we know that cls is a class or function,
# and not on the exclude list
run, reason = _run_test_for_class(cls, only_changed_modules=ONLY_CHANGED_MODULES)
run, reason = _run_test_for_class(
cls, only_changed_modules=ONLY_CHANGED_MODULES, skip_vm_tests=SKIP_VM_TESTS
)
return _return(run, reason)


Expand All @@ -154,6 +156,7 @@ def _run_test_for_class(
ignore_deps=False,
only_changed_modules=True,
only_vm_required=False,
skip_vm_tests=False,
):
"""Check if test should run - cached with hashable cls.

Expand All @@ -171,6 +174,10 @@ class for which to determine whether it should be tested
whether th return only classes that require their own VM.
If True, will only return classes with tag "tests:vm"=True.
If False, will only return classes with tag "tests:vm"=False.
skip_vm_tests : boolean, default=False
whether to skip tests for classes that require their own VM.
If True, will skip classes with tag "tests:vm"=True.
This is useful in CI/CD where VM tests are run separately.

Returns
-------
Expand Down Expand Up @@ -261,8 +268,8 @@ def _is_impacted_by_lib_dep_change(cls, only_changed_modules):
return False, "False_required_deps_missing"
# otherwise, continue

# if only_vm_required=False, and the class requires a test vm, skip
if not only_vm_required and _requires_vm(cls):
# if skip_vm_tests=True, and the class requires a test vm, skip
if skip_vm_tests and _requires_vm(cls):
return False, "False_requires_vm"
# if only_vm_required=True, and the class does not require a test vm, skip
if only_vm_required and not _requires_vm(cls):
Expand Down
Loading