Skip to content

Move global test exporter and get_trace out of conftest.py into proper module #1181

@bloodearnest

Description

@bloodearnest

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions