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

Allow using -p no:legacypath with pytest >= 7 #213

Merged
merged 1 commit into from Nov 22, 2023

Conversation

eerovaher
Copy link
Contributor

The -p no:legacypath option for pytest prevents using legacy py.path and forces using pathlib from the Python standard library instead. 07e12f4 attempted to remove all uses of py.path with pytest >= 7 so that downstream packages could use that option, (at least with recent enough pytest). That commit introduced using getattr() to access the path attribute of _pytest.nodes.Node instances and falling back to the fspath attribute if path does not exist (which happens with pytest < 7). However, evaluating the default for getattr() then guarantees that fspath is accessed, which is incompatible with -p no:legacypath. The simplest way of avoiding accessing fspath is to use explicitly version-dependent code.

The `-p no:legacypath` option for `pytest` prevents using legacy
`py.path` and forces using `pathlib` from the Python standard library
instead. 07e12f4 (Remove usage of
`py.path` with `pytest` 7) attempted to remove all uses of `py.path`
with `pytest` >= 7 so that downstream packages could use that option,
(at least with recent enough `pytest`). That commit introduced using
`getattr()` to access the `path` attribute of `_pytest.nodes.Node`
instances and falling back to the `fspath` attribute if `path` does not
exist (which happens with `pytest` < 7). However, evaluating the
`default` for `getattr()` then guarantees that `fspath` is accessed,
which is incompatible with `-p no:legacypath`. The simplest way of
avoiding accessing `fspath` is to use explicitly version-dependent code.
@eerovaher eerovaher mentioned this pull request Nov 22, 2023
Copy link
Member

@ConorMacBride ConorMacBride left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Another way would be to have None as the default path attribute value and put the call to fspath after an or, but I think I prefer the explicit version check. It makes it easier to keep track of code only needed for older versions. Thanks!

@ConorMacBride ConorMacBride merged commit f27a86e into matplotlib:main Nov 22, 2023
20 of 21 checks passed
@eerovaher eerovaher deleted the no_legacypath branch November 22, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants