Skip to content

tests: clean up pytest configuration and setup#321

Merged
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:test-setup-cleanup
Apr 13, 2026
Merged

tests: clean up pytest configuration and setup#321
MaStr merged 1 commit intoMaStr:mainfrom
filiplajszczak:test-setup-cleanup

Conversation

@filiplajszczak
Copy link
Copy Markdown
Contributor

This cleans up the current pytest setup before a separate uv follow-up.

It moves the active pytest configuration into pyproject.toml, removes the now-redundant pytest.ini, and drops old manual sys.path mangling from tests that no longer need it once pytest uses pythonpath = src.

While touching test setup, it also does a small cleanup in tests/batcontrol/test_production_offset.py by switching the repeated factory patch setup there to a fixture using pytest-mock.

@MaStr MaStr merged commit 0f672d3 into MaStr:main Apr 13, 2026
12 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates pytest configuration into pyproject.toml (prepping for a future uv follow-up), removes redundant pytest/sys.path bootstrapping from tests, and refactors one test module to use a shared factory-patching fixture.

Changes:

  • Move pytest configuration from pytest.ini into pyproject.toml ([tool.pytest.ini_options]) and delete pytest.ini.
  • Remove manual sys.path manipulation from tests now that pytest adds src via pythonpath.
  • Refactor tests/batcontrol/test_production_offset.py to use a pytest-mock fixture for repeated factory patch setup.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/conftest.py Removed now-unneeded global sys.path insertion (file deleted).
tests/batcontrol/test_production_offset.py Introduced a fixture to patch core factories and reuse a Batcontrol instance in tests.
tests/batcontrol/inverter/test_mqtt_inverter.py Removed per-file sys.path insertion.
tests/batcontrol/inverter/test_dummy.py Removed per-file sys.path insertion.
pytest.ini Removed redundant pytest configuration file.
pyproject.toml Added pytest ini options under [tool.pytest.ini_options] (incl. pythonpath = ["src"]).

Comment on lines +84 to +93
def test_production_offset_initialization_default(
self, mock_config, batcontrol_with_patched_factories
):
"""Test that production offset initializes with default value when not configured"""
# Remove production_offset_percent from config
del mock_config['battery_control_expert']['production_offset_percent']

with patch('batcontrol.core.tariff_factory'), \
patch('batcontrol.core.inverter_factory'), \
patch('batcontrol.core.solar_factory'), \
patch('batcontrol.core.consumption_factory'):
batcontrol = Batcontrol(mock_config)

batcontrol = Batcontrol(mock_config)
assert batcontrol.production_offset_percent == 1.0
batcontrol.shutdown()
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_production_offset_initialization_default requests batcontrol_with_patched_factories but then instantiates a new Batcontrol(mock_config) without any factory patching. This bypasses the intended isolation (real provider factories + scheduler thread + refresh_data calls can run) and also spins up an unused extra Batcontrol instance via the fixture. Use the fixture instance for the assertion, or restructure so factory patching happens for the Batcontrol instance created after removing production_offset_percent (e.g., patch factories first, then construct Batcontrol once).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants