Add pytest plugin for automatic .coco test compilation (#888)#902
Open
ad4mf06 wants to merge 1 commit intoevhub:developfrom
Open
Add pytest plugin for automatic .coco test compilation (#888)#902ad4mf06 wants to merge 1 commit intoevhub:developfrom
ad4mf06 wants to merge 1 commit intoevhub:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR implements issue #888 by adding support for automatic compilation and execution of
.cocofiles via pytest, without requiring a prior manual compilation step.Changes
pytest_plugin.py(new file)Created a dedicated pytest plugin containing three core functions:
pytest_configure— Called at the start of the pytest session. Installs_PytestCoconutImporterat the front ofsys.meta_pathto intercept imports of.cocomodules.pytest_collect_file— Called for each discovered file. If the file matchestest_*.coco, it compiles it to a.pyfile alongside the source (not in a cache directory), then instructs pytest to collect that.pyfile. This resolves theimport file mismatcherror.pytest_ignore_collect— Prevents double-collection by ignoring thecoconut_cache/directory and any.pyfiles that have a corresponding.cocosource file.api.pyAdded a function to allow manual installation of the
pytest11entry point, enabling the plugin to be registered directly without extra configuration.setup.py/pyproject.tomlRegistered the plugin via
pytest11so it is automatically installed and activated when the package is installed._PytestCoconutImporter— 2 overridden methodsInherits from
CoconutImporterwith two overrides:compile()— Replacessys.stdinduring compilation to avoidOSErrorcaused by pytest capturing stdin.find_spec()— Returns a spec pointing to the compiled.pyfile in place, preventing the global importer from redirecting imports elsewhere.