skbase.testing.QuickTester#
- class skbase.testing.QuickTester[source]#
Mixin class which adds the run_tests method to run tests on one object.
Mixin for test classes inheriting from
scikit-baseBaseFixtureGenerator, to allow running tests on a single object instance.Methods
run_tests(obj[, raise_exceptions, ...])Run all tests on one single object.
- run_tests(obj, raise_exceptions=False, tests_to_run=None, fixtures_to_run=None, tests_to_exclude=None, fixtures_to_exclude=None, verbose=False)[source]#
Run all tests on one single object.
All tests in self are run on the following object type fixtures:
if est is a class, then
object_class=est, andobject_instanceloops overest.create_test_instance()if est is an object, then
object_class=est.__class__, andobject_instance=est
Compatibility with
pytestfixtures:run_testsis compatible withpytest.mark.parametrizedecoration, but currently only with multiple single variable annotations.the following
pytestreserved fixture names are supported:tmp_path,monkeypatch,capsys,caplog
- Parameters:
- objsubclass of scikit-base BaseObject, or instance thereof
scikit-base object class or scikit-base object instance
- raise_exceptionsbool, optional, default=False
whether to return exceptions/failures in the results dict, or raise them
if False: returns exceptions in returned
resultsdictif True: raises exceptions as they occur
- tests_to_runstr or list of str, names of tests to run. default = all tests
sub-sets tests that are run to the tests given here.
- fixtures_to_runstr or list of str, pytest test-fixture combination codes.
which test-fixture combinations to run. Default = run all of them. sub-sets tests and fixtures to run to the list given here. If both
tests_to_runandfixtures_to_runare provided, runs the union of tests implied by both, i.e., all test-fixture combinations for tests intests_to_run, plus all test-fixture combinations infixtures_to_run.- tests_to_excludestr or list of str, names of tests to exclude. default = None
removes tests that should not be run, after subsetting via
tests_to_run.- fixtures_to_excludestr or list of str, fixtures to exclude. default = None
removes test-fixture combinations that should not be run. This is done after subsetting via
fixtures_to_run.- verboseint or bool, optional, default=0.
verbosity level for printouts from tests run.
0 or False (default): no printout
1 or True: print summary of test run, but no print from tests
2: print all test output, including output from within the tests
- Returns:
- resultsdict of results of the tests in self
keys are test/fixture strings, identical as in pytest, e.g.,
test[fixture]entries are the string"PASSED"if the test passed, or the exception raised if the test did not pass.resultsis returned only if all tests pass, orraise_exceptions=False.
- Raises:
- if raise_exception=True, raises any exception produced by the tests directly
Examples
>>> from skbase.tests.mock_package.test_mock_package import CompositionDummy >>> from skbase.testing.test_all_objects import TestAllObjects >>> TestAllObjects().run_tests( ... CompositionDummy, ... tests_to_run="test_constructor" ... ) {'test_constructor[CompositionDummy]': 'PASSED'} >>> TestAllObjects().run_tests( ... CompositionDummy, fixtures_to_run="test_repr[CompositionDummy-1]" ... ) {'test_repr[CompositionDummy-1]': 'PASSED'}