test: make slow and order-dependent tests fast and independent

Slow tests:
- TestPerformance inserted 10 000 records three times per backend. One
  test per backend now times insert, save and load on the same records,
  with the same assertions.
- test_measurement_realtime_stream slept one second per update, 20 s per
  backend. The updates use synthetic timestamps one second apart in the
  recent past, without a pause, and send the same duplicates,
  out-of-order and burst writes.
- test_readers_never_see_a_partial_document: the readers spun on the
  cache and kept the writer waiting for the GIL (~50 s). They now yield
  with time.sleep(0) after each lookup (~0.5 s); a non-atomic save still
  fails the test 10 of 10 times.
- test_devicessettingsbattery.py compiled the same plain profile before
  each of its 235 tests. A module-scoped fixture compiles it once; a
  compiled profile is frozen and may be shared (20.8 s -> 9.4 s).
- The --finalize case of test_geneticoptimize.py runs 250 instead of
  400 generations. For this input and seed the best fitness is final in
  generation 213, and the solutions after 250 and 400 generations are
  identical field by field. The test checks the keys and the consistency
  of the result, not the schedule, so it detects the same as before
  (127 s -> 80 s on GitHub runners). test_genetic0optimize.py keeps 400.

Tests that depended on another test of the same process, found by
running them in another order and under pytest-xdist:
- TestPredictionContainer::test_len relied on a class flag that a
  TestPredictionProvider fixture set and never reset. Both fixtures now
  set the flags with monkeypatch.
- The EnergyCharts status code test got a cached response from an
  earlier test; it now calls _request_forecast(force_update=True) and
  asserts that the request was made.
- test_ingress_safe_links did not wait for EOSdash, which EOS starts
  after its own startup.
- test_forward_stream_truncates_very_long_line found the log queue left
  behind by test_server_start_eosdash (no worker, closed event loop). It
  installs its own queue now, and test_server_start_eosdash no longer
  leaves its queue behind. Dropping lines from a full queue was only
  covered through that left-over queue and gets a test of its own.

Refs #1553

Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-fable-5-2)
This commit is contained in:
Christin
2026-11-20 07:15:33 +01:00
committed by Bobby Noelte
co-authored by SchaafAlexander Claude Opus 5.5
parent ce7fb96faf
commit e2726354c2
10 changed files with 99 additions and 62 deletions
+8 -4
View File
@@ -132,10 +132,11 @@ class TestPredictionABC:
class TestPredictionProvider:
# Fixtures and helper functions
@pytest.fixture
def provider(self):
def provider(self, monkeypatch):
"""Fixture to provide an instance of TestPredictionProvider for testing."""
DerivedPredictionProvider.provider_enabled = True
DerivedPredictionProvider.provider_updated = False
# monkeypatch restores the class flags, so later tests do not inherit them.
monkeypatch.setattr(DerivedPredictionProvider, "provider_enabled", True)
monkeypatch.setattr(DerivedPredictionProvider, "provider_updated", False)
return DerivedPredictionProvider()
@pytest.fixture
@@ -247,7 +248,10 @@ class TestPredictionContainer:
return container
@pytest_asyncio.fixture
async def container_with_providers(self):
async def container_with_providers(self, monkeypatch):
# The container only counts enabled providers. Enable it here instead of relying
# on a TestPredictionProvider test having run before in the same process.
monkeypatch.setattr(DerivedPredictionProvider, "provider_enabled", True)
records = [
# Test records - include 'prediction_value' key
self.create_test_record(datetime(2023, 11, 5), 1),