From 35430b5fd23ad5f700bd1f11533c30406980e94c Mon Sep 17 00:00:00 2001 From: Alenka Frim Date: Mon, 16 Jan 2023 08:55:45 +0100 Subject: [PATCH] Update pytest_collect_file to take into account fspath deprecation in Node constructors --- src/pytest_cython/plugin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pytest_cython/plugin.py b/src/pytest_cython/plugin.py index 7dc4523..15bfa57 100644 --- a/src/pytest_cython/plugin.py +++ b/src/pytest_cython/plugin.py @@ -7,6 +7,7 @@ import pytest import py.path +from pathlib import Path import _pytest from _pytest.doctest import get_optionflags @@ -54,7 +55,12 @@ def pytest_collect_file(path, parent): # only run test if matching .so and .pyx files exist # create addoption for this ?? if hasattr(DoctestModule, 'from_parent'): - return DoctestModule.from_parent(parent, fspath=path) + try: + # fspath for Node constructors deprecated since + # pytest version 7.0., replaced with pathlib.Path + return DoctestModule.from_parent(parent, path=Path(str(path))) + except TypeError: + return DoctestModule.from_parent(parent, fspath=path) else: # Backwards-compat for older pytest return DoctestModule(path, parent)