Our conftest.py sets up a testing otel setup, with a global instance of an InMemoryExporter, which tests can call get_trace() on to get any spans that were generated during the tests.
The get_trace() function was implemented in tests/conftest.py, and explicitly imported from conftest in tests that needed it.
This was a bad idea, it turns out, as pytest doesn't actually import conftest.py as part of its set up, just loads it. To it gets "imported" twice, which resets the globals.
It happened to have not caused any issues, but it did when pulling jobrunner into opensafely-cli. The fix there was to put the global InMemoryExporter in tests.factories, which is always properly imported.
Be worth doing that in production job-runner too.
Our conftest.py sets up a testing otel setup, with a global instance of an InMemoryExporter, which tests can call get_trace() on to get any spans that were generated during the tests.
The get_trace() function was implemented in tests/conftest.py, and explicitly imported from conftest in tests that needed it.
This was a bad idea, it turns out, as pytest doesn't actually import conftest.py as part of its set up, just loads it. To it gets "imported" twice, which resets the globals.
It happened to have not caused any issues, but it did when pulling jobrunner into opensafely-cli. The fix there was to put the global InMemoryExporter in tests.factories, which is always properly imported.
Be worth doing that in production job-runner too.