refactor: migrate to hatchling and simplify test setup#9
Conversation
Switch from setuptools to hatchling for build system and remove manual sys.path setup from tests since it's no longer needed.
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the Python build backend to Hatchling, removes ad-hoc sys.path hacks from tests, and streamlines test setup by collapsing multi-line patches and concatenations into single-line expressions.
- Switched from
setuptoolstohatchlinginpyproject.tomland added basic pytest settings. - Stripped out all manual
sys.pathinserts in test files, relying on pytest’s configuration instead. - Refactored test code to use single-line statements for list/tuple definitions, patch contexts, and async loops for readability.
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Migrated build backend to Hatchling; added pytest.ini options |
| tests/test_web.py | Removed sys.path manipulation; simplified string builds |
| tests/test_views.py | Removed sys.path; collapsed multi-line async for loops |
| tests/test_ui_integration.py | Removed sys.path; combined tuple definitions into one line |
| tests/test_scroll_management.py | Removed sys.path; simplified method call argument layout |
| tests/test_performance.py | Removed sys.path; reordered imports and assertion format |
| tests/test_navigation.py | Removed sys.path; collapsed patch contexts and loops |
| tests/test_main.py | Removed sys.path; reordered imports |
| tests/test_llm.py | Removed sys.path; reordered imports; streamlined assignments |
| tests/test_content_processing.py | Removed sys.path; simplified patch statements |
| tests/test_config.py | Removed sys.path; reordered imports |
Comments suppressed due to low confidence (2)
tests/test_views.py:1
- [nitpick] Consider grouping imports into standard library, third-party, and local sections (with blank lines between) to comply with PEP8 import ordering and improve readability.
from unittest.mock import Mock
pyproject.toml:63
- Verify that the pytest
pythonpathsetting undertool.pytest.ini_optionsis supported without additional plugins; otherwise tests may still fail to locate thesrcpackage.
pythonpath = ["src"]
tests/test_scroll_management.py
Outdated
| self.mock_content_widget.max_scroll_y = property( | ||
| lambda self: exec('raise Exception("Test error")') | ||
| ) | ||
| self.mock_content_widget.max_scroll_y = property(lambda self: exec('raise Exception("Test error")')) |
There was a problem hiding this comment.
[nitpick] Using exec inside a lambda to raise an exception is hard to read; consider defining a simple property that directly raises for clarity in the test.
| self.mock_content_widget.max_scroll_y = property(lambda self: exec('raise Exception("Test error")')) | |
| def raise_exception(): | |
| raise Exception("Test error") | |
| self.mock_content_widget.max_scroll_y = property(lambda _: raise_exception()) |
|
This looks great! I added a formatting check in the CI, just run |
|
Done! Also on the other PR I just added :) That's probably all I'll do for this weekend, but I might take a crack at a few other things during breaks at work this week. |
|
Amazing, thank you! |
This pull request introduces updates to the project's build system, dependencies, and testing structure. The most notable changes include migrating from
setuptoolstohatchlingfor the build system, removing the need to modifysys.pathin test files, and simplifying patching logic in tests for better readability and maintainability.The Build system is much faster and all of the sys path manipulation is no longer needed. All tests are still passing.
Build System and Dependency Updates:
setuptoolstohatchlingas the build backend inpyproject.toml. This involved updating therequiresfield under[build-system]and removingtool.setuptoolsconfigurations.License :: OSI Approved :: MIT Licenseto theclassifierssection inpyproject.toml.Test File Improvements:
sys.pathmodifications from all test files, eliminating the need for manual inclusion of the project directory for testing. This change affects files such astests/test_config.py,tests/test_content_processing.py,tests/test_llm.py,tests/test_main.py, andtests/test_navigation.py. [1] [2] [3] [4] [5]with patchstatements into single-line statements for better readability. Examples includetests/test_content_processing.pyandtests/test_llm.py. [1] [2]