make test-unitOTEL tests use async background threads (OTEL BatchSpanProcessor) that can cause test pollution when tests run in the same process. The Makefile is configured to run these tests with process isolation using pytest-xdist.
Prerequisites:
poetry install --with dev # Installs pytest-xdistRun OTEL tests individually (always works):
TEST_OPTIONAL=1 poetry run pytest tests/unit/test_otel_inline_evaluations.py -v
TEST_OPTIONAL=1 poetry run pytest tests/unit/test_otel_tru_chain.py -v
TEST_OPTIONAL=1 poetry run pytest tests/unit/test_otel_tru_graph.py -v
# ... etcRun OTEL tests with isolation (requires pytest-xdist):
TEST_OPTIONAL=1 poetry run pytest tests/unit/test_otel*.py -n auto --dist=loadscopeWhy isolation is needed:
- OTEL spans are written asynchronously by background threads
force_flush()signals the batch processor but doesn't guarantee completion- Tests may see events from previous tests even after database reset
- Running each test file or test class in a separate process guarantees isolation
@pytest.mark.optional: Requires optional dependencies (LangChain, LlamaIndex, LangGraph)@pytest.mark.snowflake: Requires Snowflake credentials@pytest.mark.huggingface: Requires HuggingFace API access
Enable optional tests:
TEST_OPTIONAL=1 make test-unitSome tests use golden files (CSV snapshots) for regression testing. To regenerate:
WRITE_GOLDEN=1 TEST_OPTIONAL=1 poetry run pytest tests/unit/test_otel_tru_chain.py::TestOtelTruChain::test_smokeImportant: Only regenerate golden files when you've verified the new behavior is correct!
This is expected if pytest-xdist is not installed. Install it with:
poetry install --with devThen run via Makefile which uses proper isolation:
make test-unitUse make test-unit which handles isolation, or run test files individually.