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

fix: remove legacy path usage to support no:legacypath, closes #677 #684

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions src/syrupy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/syrupy/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simplest to just convert Path to a string for now, can be cleaned up later to just use Path objects everywhere

obj = getattr(self._node, "obj") # noqa: B009
self.modulename = obj.__module__
self.methodname = obj.__name__
Expand Down
2 changes: 1 addition & 1 deletion src/syrupy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions src/syrupy/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions stubs/pytest.pyi

This file was deleted.

2 changes: 1 addition & 1 deletion tests/syrupy/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down