Erotemic / xdoctest

A rewrite of Python's builtin doctest module (with pytest plugin integration) with AST instead of REGEX.
Apache License 2.0
205 stars 12 forks source link

Fix Pytest 8 compatibility #119

Closed amolenaar closed 2 years ago

amolenaar commented 2 years ago

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.

Erotemic commented 2 years ago

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?

amolenaar commented 2 years ago

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 :disappointed:.

codecov[bot] commented 2 years ago

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 commented 2 years ago

LGTM.

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

Erotemic commented 2 years ago

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