From eefa37d83fb437c60d9425d22bcebb8c6621af08 Mon Sep 17 00:00:00 2001 From: Ken Sanislo Date: Fri, 15 May 2026 12:27:25 -0700 Subject: [PATCH] tests: isolate solaar.configuration from the real config file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/conftest.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..b4ec0f88 --- /dev/null +++ b/tests/conftest.py @@ -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", [])