baseobject.testing.TestAllObjects#
- class baseobject.testing.TestAllObjects[source]#
Package level tests for BaseObjects.
- Attributes:
- exclude_objects
- excluded_tests
- object_type_filter
- valid_base_types
- valid_tags
Methods
Return dict with methods _generate_[variable] collected in a dict.
is_excluded(test_name, est)Shorthand to check whether test test_name is excluded for object est.
object_instance(request)object_instance fixture definition for indirect use.
pytest_generate_tests(metafunc)Test parameterization routine for pytest.
run_tests(obj[, return_exceptions, ...])Run all tests on one single object.
test_clone(object_instance)Check we can call clone from scikit-learn.
test_constructor(object_class)Check that the constructor has correct signature and behaves correctly.
test_create_test_instance(object_class)Check first that create_test_instance logic works.
Check that create_test_instances_and_names works.
test_get_params(object_instance)Check that get_params works correctly.
test_inheritance(object_class)Check that object inherits from BaseObject.
Test that there are no side effects across instances of the same test.
Test that there are no side effects across tests, through object state.
Test that there are no side effects across tests, through object state.
test_object_tags(object_class)Check conventions on object tags.
test_repr(object_instance)Check we can call repr.
test_set_params(object_instance)Check that set_params works correctly.
test_set_params_sklearn(object_class)Check that set_params works correctly, mirrors sklearn check_set_params.
test_valid_object_class_tags(object_class)Check that object class tags are in self.valid_tags.
test_valid_object_tags(object_instance)Check that object tags are in self.valid_tags.
- test_create_test_instances_and_names(object_class)[source]#
Check that create_test_instances_and_names works.
- test_no_cross_test_side_effects_part1(object_instance)[source]#
Test that there are no side effects across tests, through object state.
- test_no_cross_test_side_effects_part2(object_instance)[source]#
Test that there are no side effects across tests, through object state.
- test_no_between_test_case_side_effects(object_instance, a)[source]#
Test that there are no side effects across instances of the same test.
- test_set_params_sklearn(object_class)[source]#
Check that set_params works correctly, mirrors sklearn check_set_params.
Instead of the “fuzz values” in sklearn’s check_set_params, we use the other test parameter settings (which are assumed valid). This guarantees settings which play along with the __init__ content.
- test_constructor(object_class)[source]#
Check that the constructor has correct signature and behaves correctly.
- test_valid_object_class_tags(object_class)[source]#
Check that object class tags are in self.valid_tags.
- generator_dict()[source]#
Return dict with methods _generate_[variable] collected in a dict.
- The returned dict is the one required by create_conditional_fixtures_and_names,
used in this _conditional_fixture plug-in to pytest_generate_tests, above.
- Returns:
- generator_dictdict, with keys [variable], where
- [variable] are all strings such that self has a static method
named _generate_[variable](test_name: str, **kwargs)
value at [variable] is a reference to _generate_[variable]
- is_excluded(test_name, est)[source]#
Shorthand to check whether test test_name is excluded for object est.
- pytest_generate_tests(metafunc)[source]#
Test parameterization routine for pytest.
This uses create_conditional_fixtures_and_names and generator_dict to create the fixtures for a mark.parametrize decoration of all tests.
- run_tests(obj, return_exceptions=True, tests_to_run=None, fixtures_to_run=None, tests_to_exclude=None, fixtures_to_exclude=None)[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, and
object_instance loops over est.create_test_instance()
- if est is an object, then object_class = est.__class__, and
object_instance = est
- This is compatible with pytest.mark.parametrize decoration,
but currently only with multiple single variable annotations.
- Parameters:
- objobject class or object instance
- return_exceptionsbool, optional, default=True
- whether to return exceptions/failures, or raise them
if True: returns exceptions in results if False: 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_run and fixtures_to_run are provided, runs the union, i.e., all test-fixture combinations for tests in tests_to_run,
plus all test-fixture combinations in fixtures_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.
- 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
returned only if all tests pass, or return_exceptions=True
- Raises:
- if return_exception=False, raises any exception produced by the tests directly
Examples
>>> from baseobject.mock_package import CompositionDummy >>> from baseobject.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'}