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

Pytest is deprecating fspath in favor of pathlib.Path #24

Open
shvenkat opened this issue Mar 11, 2022 · 1 comment · Fixed by #26
Open

Pytest is deprecating fspath in favor of pathlib.Path #24

shvenkat opened this issue Mar 11, 2022 · 1 comment · Fixed by #26

Comments

@shvenkat
Copy link

shvenkat commented Mar 11, 2022

Thanks for providing the package. It was just what I needed, and it "just worked"!

Similar to #3, running pytest --doctest-cython works, but gives the following warning:

<some_path>/python3.10/site-packages/_pytest/nodes.py:140
  <some_path>/python3.10/site-packages/_pytest/nodes.py:140: PytestRemovedIn8Warning: The (fspath: py.path.local) argument to DoctestModule 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)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

I tried the following as a quick fix, and it works. I just don't know if I'm breaking something else (like special handling for win32 paths). Also, it looks like there are other uses of fspath in plugin.py that may also need to be fixed.

--- a/pytest_cython/plugin.py
+++ b/pytest_cython/plugin.py
@@ -6,6 +6,7 @@
 import sys
 import tokenize
 import pytest
+from pathlib import Path
 
 try:
     import sysconfig
@@ -71,7 +72,7 @@
             # create addoption for this ??
             if pyx_file is not None:
                 if hasattr(DoctestModule, 'from_parent'):
-                    return DoctestModule.from_parent(parent, fspath=path)
+                    return DoctestModule.from_parent(parent, path=Path(str(path)))
                 else:
                     # Backwards-compat for older pytest
                     return DoctestModule(path, parent)

Info

Python 3.10.2
pytest 7.0.1
pytest-cov 3.0.0
pytest-cython 0.1.1.post0
pytest-randomly 3.11.0

@pitrou
Copy link

pitrou commented Dec 12, 2024

It seems like a similar issue is remaining in pytest-cython 0.3.1:
https://github.com/ursacomputing/crossbow/actions/runs/12296705269/job/34316261656#step:7:5932

+ pytest -r s -m hypothesis -W error --pyargs pyarrow
/opt/conda/envs/arrow/lib/python3.11/site-packages/pytest_cython/__init__.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import get_distribution
/opt/conda/envs/arrow/lib/python3.11/site-packages/pkg_resources/__init__.py:3154: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/opt/conda/envs/arrow/lib/python3.11/site-packages/pytest_cython/plugin.py:36: PytestRemovedIn9Warning: The (path: py.path.local) argument is deprecated, please use (file_path: pathlib.Path)
see https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path
  def pytest_collect_file(file_path: pathlib.Path, path, parent: pytest.Collector) -> pytest.Module:

cc @AlenkaF @lgpage

@lgpage lgpage reopened this Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants