Skip to content

fix: reset LocalDataService singleton between tests#1784

Open
filippsatverily wants to merge 1 commit into
cdisc-org:mainfrom
filippsatverily:filipps/fix-pytest9-singleton-leak
Open

fix: reset LocalDataService singleton between tests#1784
filippsatverily wants to merge 1 commit into
cdisc-org:mainfrom
filippsatverily:filipps/fix-pytest9-singleton-leak

Conversation

@filippsatverily

Copy link
Copy Markdown
Contributor

Several tests mutate the LocalDataService singleton (overwriting get_datasets, get_dataset, dataset_implementation, etc.) without restoring the original state. With pytest <8 the default collection order happened to run test_rules_engine.py before the mutating tests, masking the issue. Pytest 9 changed the collection order, exposing 29 test failures from stale singleton state.

This adds an autouse fixture in conftest.py that resets LocalDataService._instance = None after each test. This doesn't change the pytest version constraint — it just makes the test suite order-independent so pytest can be upgraded when ready.

Tested scenarios:

  • Full pytest suite with pytest 7.4: 1746 passed, 11 skipped, 0 failed
  • Full pytest suite with pytest 9.1.1: 1746 passed, 11 skipped, 0 failed

Several tests mutate the LocalDataService singleton (overwriting
get_datasets, get_dataset, dataset_implementation, etc.) without
restoring the original state. With pytest <8 the default collection
order happened to run test_rules_engine.py before the mutating tests,
masking the issue. Pytest 9 changed collection order, exposing 29
failures from stale singleton state.

Adding an autouse fixture that resets the singleton after each test.
@filippsatverily filippsatverily marked this pull request as ready for review June 23, 2026 22:43
@filippsatverily

Copy link
Copy Markdown
Contributor Author

@SFJohnson24 this allows bumping pytest. We could fix the tests that modify the singleton, but there are a lot of them, so I went with a reset per test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant