Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pytest 8 compatibility #119

Merged
merged 2 commits into from Mar 25, 2022
Merged

Conversation

amolenaar
Copy link
Contributor

Pytest is moving away from py.path.local to pathlib.Path.

This causes warnings when running tests on Pytest 7:

.venv/lib/python3.10/site-packages/_pytest/nodes.py:140: 481 warnings
  /home/arjan/Development/gaphor/.venv/lib/python3.10/site-packages/_pytest/nodes.py:140: PytestRemovedIn8Warning: The (fspath: py.path.local) argument to XDoctestModule is deprecated. Please use the (path: pathlib.Path) argument instead.
  See https://docs.pytest.org/en/latest/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path
    return super().__call__(*k, **kw)

See also https://docs.pytest.org/en/7.0.x/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path.

This PR changes the pytest_collect_file function to use the pathlib path objects instead.

@amolenaar amolenaar changed the title Fix Pytest 8 compatibility issues Fix Pytest 8 compatibility Mar 24, 2022
@Erotemic
Copy link
Owner

Erotemic commented Mar 24, 2022

Thank you for the PR. Definitely want to get this fixed.

Does the minimum version of pytest need to be updated in requirements/tests.txt?

I'm also not sure why the dashboards aren't running. I just merged dev/0.5.11 into main, which adds support for "loose" and "strict" requirement tests. (i.e. strict runs with minimum versions of everything, and loose runs with latest versions of everything). We need to ensure this doesn't break anyone using minimum versions.

Can you rebase on the latest main and see if that causes the dashboards to run?

@Erotemic Erotemic added the bug label Mar 24, 2022
Pytest is moving away from `py.path.local` to `pathlib`.

This causes warnings when running tests on Pytest 7.
@amolenaar
Copy link
Contributor Author

Good point. From what I read in the docs, the file_path attribute was only added in Pytest 7.0. That would imply this PR breaks with any version of Pytest < 7.0 😞.

@amolenaar amolenaar force-pushed the pytest8-compat branch 3 times, most recently from 8d5dfee to 8713b01 Compare March 24, 2022 19:19
The new form (using Pathlib) is introduced in Pytest 7. We still want to
support older versions.
@codecov
Copy link

codecov bot commented Mar 25, 2022

Codecov Report

Merging #119 (d000246) into main (4ef9b23) will decrease coverage by 2.46%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #119      +/-   ##
==========================================
- Coverage   84.24%   81.78%   -2.47%     
==========================================
  Files          26       26              
  Lines        3022     3025       +3     
  Branches      666      643      -23     
==========================================
- Hits         2546     2474      -72     
- Misses        376      448      +72     
- Partials      100      103       +3     

@Erotemic
Copy link
Owner

LGTM.

Last question: if pytest.__version__ < '7.': is that robust to edge cases? Would something like distutils.version.LooseVersion or packaging.version.Version?

@Erotemic
Copy link
Owner

I tested the above question. Looks like that code is robust without requiring extra imports. Thanks for the patch!

@Erotemic Erotemic merged commit 8658994 into Erotemic:main Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants