diff --git a/pyproject.toml b/pyproject.toml index ef27718d..a8d90cfc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,7 @@ dist, ''' [tool.pytest.ini_options] -addopts = '-p syrupy --doctest-modules' +addopts = '-p syrupy -p pytester -p no:legacypath --doctest-modules' testpaths = ['tests'] [tool.coverage.run] diff --git a/src/syrupy/__init__.py b/src/syrupy/__init__.py index 04020d20..5f1a646c 100644 --- a/src/syrupy/__init__.py +++ b/src/syrupy/__init__.py @@ -162,13 +162,13 @@ def pytest_runtest_logfinish(nodeid: str) -> None: _syrupy.ran_item(nodeid) -@pytest.hookimpl(tryfirst=True) -def pytest_sessionfinish(session: Any, exitstatus: int) -> None: +@pytest.hookimpl(tryfirst=True) # type: ignore[misc] +def pytest_sessionfinish(session: "pytest.Session", exitstatus: int) -> None: """ Finish session run and set exit status. https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_sessionfinish """ - session.exitstatus |= exitstatus | session.config._syrupy.finish() + session.exitstatus |= exitstatus | session.config._syrupy.finish() # type: ignore[attr-defined] # noqa: E501 def pytest_terminal_summary( diff --git a/src/syrupy/location.py b/src/syrupy/location.py index 931e462b..3d8fe2d4 100644 --- a/src/syrupy/location.py +++ b/src/syrupy/location.py @@ -28,7 +28,8 @@ def __post_init__(self) -> None: self.__attrs_post_init_def__() def __attrs_post_init_def__(self) -> None: - self.filepath = getattr(self._node, "fspath") # noqa: B009 + node_path: Path = getattr(self._node, "path") # noqa: B009 + self.filepath = str(node_path.absolute()) obj = getattr(self._node, "obj") # noqa: B009 self.modulename = obj.__module__ self.methodname = obj.__name__ diff --git a/src/syrupy/report.py b/src/syrupy/report.py index 32f3e732..4088be4e 100644 --- a/src/syrupy/report.py +++ b/src/syrupy/report.py @@ -55,7 +55,7 @@ class SnapshotReport: """ # Initial arguments to the report - base_dir: str + base_dir: Path collected_items: Set["pytest.Item"] selected_items: Dict[str, bool] options: "argparse.Namespace" diff --git a/src/syrupy/session.py b/src/syrupy/session.py index f5cc3516..6b612145 100644 --- a/src/syrupy/session.py +++ b/src/syrupy/session.py @@ -39,8 +39,7 @@ @dataclass class SnapshotSession: - # pytest.Session - pytest_session: Any + pytest_session: "pytest.Session" # Snapshot report generated on finish report: Optional["SnapshotReport"] = None # All the collected test items @@ -116,7 +115,7 @@ def finish(self) -> int: exitstatus = 0 self.flush_snapshot_write_queue() self.report = SnapshotReport( - base_dir=self.pytest_session.config.rootdir, + base_dir=self.pytest_session.config.rootpath, collected_items=self._collected_items, selected_items=self._selected_items, assertions=self._assertions, diff --git a/stubs/pytest.pyi b/stubs/pytest.pyi deleted file mode 100644 index bfdf4e75..00000000 --- a/stubs/pytest.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import ( - Any, - Callable, - TypeVar, -) - -ReturnType = TypeVar("ReturnType") - -def hookimpl(tryfirst: bool) -> Callable[..., Any]: ... -def fixture(func: Callable[..., ReturnType]) -> Callable[..., ReturnType]: ... - -class Function: ... -class Item: ... diff --git a/tests/syrupy/test_location.py b/tests/syrupy/test_location.py index 4bf79920..2e3ff0c6 100644 --- a/tests/syrupy/test_location.py +++ b/tests/syrupy/test_location.py @@ -11,7 +11,7 @@ def mock_pytest_item(node_id: str, method_name: str) -> "pytest.Item": mock_node.nodeid = node_id [filepath, *_, nodename] = node_id.split("::") mock_node.name = nodename - mock_node.fspath = filepath + mock_node.path = Path(filepath) mock_node.obj = MagicMock() mock_node.obj.__module__ = Path(filepath).stem mock_node.obj.__name__ = method_name