Fix ModuleNotFoundError in test collection caused by absolute import in __init__.py #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the Pull Request
Pytest test collection fails with
ModuleNotFoundError: No module named 'main'when importing__init__.pyfrom certain directory contexts. The absolute importfrom main import workoutdoesn't resolve when the package is imported from a parent directory during test discovery.Expected Behavior
Tests should collect and run successfully regardless of the directory context from which pytest is invoked.
Fixes the Following Issues
Resolves the test collection errors reported in the testing workflow:
ERROR collecting tests/test_gui.py- ImportError at__init__.py:4ERROR collecting tests/test_main.py- ImportError at__init__.py:4Changes
Modified
__init__.pyto handle both absolute and relative import contexts:This allows the import to succeed when:
Desktop Developed On (please complete the following information):
Additional Context
The fix maintains backward compatibility with existing import patterns while enabling proper test discovery. No functional changes to the
workout()function or test suite.Please ensure you have read the Contributor License Agreements. By creating your pull request, you agree to the CLA.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.