cwacek / python-jsonschema-objects

Automatic Python binding generation from JSON Schemas
MIT License
363 stars 96 forks source link

tox.ini coverage command broken on Windows #250

Closed EliahKagan closed 1 year ago

EliahKagan commented 1 year ago

This project and its tests are multiplatform and support Windows, but the coverage run {envbindir}/pytest ... command used in tox.ini does not. At first I feared I may have introduced this incompatibility in #244, but I've tested the code from before that change and it has the same issue.

The core problem is that coverage run {envbindir}/pytest requires pytest to be a Python source code file. On most platforms, console_scripts stubs, such as pytest and the old py.test command, are actual Python scripts. But on Windows, they are binaries.

This can be solved by using the coverage run -m pytest form instead. #251 includes this fix.

Technical details of the bug follow below.

Error messages and debugging

Running tox to attempt to run the tests on a Windows system fails, with error messages like:

No file to run: 'C:\Users\ek\source\repos\python-jsonschema-objects\.tox\py37-jsonschema23-markdown2\Scripts/pytest'

That error message actually speaks to a different issue: coverage doesn't find a file called pytest because, on Windows, it is called pytest.exe. To show that this is merely masking the issue of that file being a binary executable, I created a virtual environment and ran the command with the .exe suffix, which produces this error:

C:\Users\ek\source\repos\python-jsonschema-objects\.venv\Lib\site-packages\coverage\control.py:883: CoverageWarning: No data was collected. (no-data-collected)
  self._warn("No data was collected.", slug="no-data-collected")
Couldn't run 'C:\Users\ek\source\repos\python-jsonschema-objects\.venv\Scripts\pytest.exe' as Python code: SyntaxError: invalid or missing encoding declaration

Therefore, this cannot be fixed by modifying how the path tp pytest is constructed in tox.ini so that it includes an .exe suffix on Windows.

Relationship to recent changes

In #244, I changed a python -m coverage to coverage. I also changed py.test to pytest.

Since the problem here is due to how coverage runs pytest, rather than how coverage is itself run, and since pytest and the old py.test command are both console_scripts stubs that are implemented as Python stub scripts on most platforms but as binary executable stubs on Windows, the changes in #244 are independent of this issue.