crom icon indicating copy to clipboard operation
crom copied to clipboard

Fix flaky tests by cleaning a polluted state.

Open sturmianseq opened this issue 3 years ago • 0 comments

What is the purpose of the change

This PR is to fix flaky tests tests/test_model.py::TestMagicMethods::test_not_multiple_instance, tests/test_model.py::TestMagicMethods::test_validate_multiplicity after running tests/test_model.py::TestAutoIdentifiers::test_bad_autoid, but pass when they are run in isolation.

Reproduce the test failure

Run the following command:

python -m pytest tests/test_model.py::TestAutoIdentifiers::test_bad_autoid tests/test_model.py::TestMagicMethods::test_not_multiple_instance

python -m pytest tests/test_model.py::TestAutoIdentifiers::test_bad_autoid tests/test_model.py::TestMagicMethods::test_validate_multiplicity

Expexted result

Test tests/test_model.py::TestMagicMethods::test_not_multiple_instance and tests/test_model.py::TestMagicMethods::test_validate_multiplicity should pass after running tests/test_model.py::TestAutoIdentifiers::test_bad_autoid.

Actual result

tests/test_model.py::TestMagicMethods::test_not_multiple_instance and tests/test_model.py::TestMagicMethods::test_validate_multiplicity fail:

        else:
>               raise ConfigurationError("Unknown auto-id type")
E     cromulent.model.ConfigurationError: Unknown auto-id type

cromulent/model.py:281: ConfigurationError

Why they fail

model.factory.auto_id_type is polluted after tests/test_model.py::TestAutoIdentifiers::test_bad_autoid

Fix

Reset model.factory.auto_id_type to int-per-segment at the end of tests/test_model.py::TestAutoIdentifiers::test_bad_autoid to avoid flaky tests.

sturmianseq avatar Nov 15 '21 17:11 sturmianseq