Three tests fail intermittently when the whole suite runs, across two files:
tests/test_emissions_tracker_flush.py::test_carbon_tracker_offline_flush
tests/test_logging_output.py::test_carbon_tracker_offline_logging_output
The failures are row counts (0 == 1, 2 == 3), so an expected measurement did not land before the assertion. Each test passes in isolation, and it reproduces on master, not just on feature branches.
The most likely cause is how CI runs the suite. .github/workflows/test-package.yml:36 is:
uv run codecarbon monitor -- uv run task test-coverage
so a live tracker wraps the entire test run. It holds /tmp/.codecarbon.lock and writes its own emissions.csv in the repo root for as long as the tests execute, while the tests under it are starting and stopping their own trackers. That is a real interaction and it is not present when you run a single test locally.
Two smaller things that make it worse:
tests/test_logging_output.py builds three trackers with no output_dir and no output_file (lines 48-52, 64-69, and the @track_emissions decorator at 81-85), so they all default to emissions.csv in the current working directory. Nothing cleans that up.
- Both files use a fixed filename in
tempfile.gettempdir() (emissions-test-TestCarbonTrackerFlush.csv, emissions-test-TestCarbonLoggingOutput.log) with no per-run suffix, and setUp/tearDown both delete it.
PeriodicScheduler chaining a threading.Timer per tick may also contribute, since a tracker a test does not stop keeps firing into the next test and tests/conftest.py only clears the hardware probe caches. Unverified. The re-arming timer goes away with #1339 / #1324, so it is worth re-measuring after one of those lands.
Likely fixes: give the logging test an explicit output_dir, make the temp filenames unique per process, and stop asserting on wall-clock-dependent row counts.
Three tests fail intermittently when the whole suite runs, across two files:
tests/test_emissions_tracker_flush.py::test_carbon_tracker_offline_flushtests/test_logging_output.py::test_carbon_tracker_offline_logging_outputThe failures are row counts (
0 == 1,2 == 3), so an expected measurement did not land before the assertion. Each test passes in isolation, and it reproduces onmaster, not just on feature branches.The most likely cause is how CI runs the suite.
.github/workflows/test-package.yml:36is:so a live tracker wraps the entire test run. It holds
/tmp/.codecarbon.lockand writes its ownemissions.csvin the repo root for as long as the tests execute, while the tests under it are starting and stopping their own trackers. That is a real interaction and it is not present when you run a single test locally.Two smaller things that make it worse:
tests/test_logging_output.pybuilds three trackers with nooutput_dirand nooutput_file(lines 48-52, 64-69, and the@track_emissionsdecorator at 81-85), so they all default toemissions.csvin the current working directory. Nothing cleans that up.tempfile.gettempdir()(emissions-test-TestCarbonTrackerFlush.csv,emissions-test-TestCarbonLoggingOutput.log) with no per-run suffix, andsetUp/tearDownboth delete it.PeriodicSchedulerchaining athreading.Timerper tick may also contribute, since a tracker a test does not stop keeps firing into the next test andtests/conftest.pyonly clears the hardware probe caches. Unverified. The re-arming timer goes away with #1339 / #1324, so it is worth re-measuring after one of those lands.Likely fixes: give the logging test an explicit
output_dir, make the temp filenames unique per process, and stop asserting on wall-clock-dependent row counts.