tests: isolate solaar.configuration from the real config file

Tests build FakeDevices named "TestDevice". Any test that touches
device.settings or device.persister without mocking
configuration.persister (e.g. test_device_complex, test_device_battery)
calls the real configuration.persister(), which loads and rewrites
~/.config/solaar/config.yaml — the TestDevice has no stable identity
so it never matches an existing entry, and a fresh blank TestDevice
entry is appended on every test run.

Add an autouse conftest fixture that points configuration's yaml/json
paths at a per-test tmp_path and clears the cached _config. No test
can reach the real config now, and each test starts from an empty
config instead of inheriting entries from earlier tests.
This commit is contained in:
Ken Sanislo 2026-05-15 12:27:25 -07:00 committed by Peter F. Patel-Schneider
parent cce8808995
commit eefa37d83f
1 changed files with 18 additions and 0 deletions

18
tests/conftest.py Normal file
View File

@ -0,0 +1,18 @@
import pytest
@pytest.fixture(autouse=True)
def isolate_solaar_configuration(tmp_path, monkeypatch):
"""Redirect solaar.configuration at a throwaway path for every test.
Tests build FakeDevices named 'TestDevice'; any that touch device.settings
or device.persister without mocking call the real configuration.persister(),
which loads and rewrites ~/.config/solaar/config.yaml appending a fresh
un-matchable TestDevice entry on every run. Pointing the paths at tmp_path
and clearing the cached _config keeps each test off the real config and
isolated from every other test."""
from solaar import configuration
monkeypatch.setattr(configuration, "_yaml_file_path", str(tmp_path / "config.yaml"))
monkeypatch.setattr(configuration, "_json_file_path", str(tmp_path / "config.json"))
monkeypatch.setattr(configuration, "_config", [])