Skip to content

Commit

Permalink
fix: remove legacy path usage to support no:legacypath, closes #677 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
noahnu committed Feb 2, 2023
1 parent 662c93f commit 6385979
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 23 deletions.
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())
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

1 comment on commit 6385979

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 6385979 Previous: 02abef5 Ratio
benchmarks/test_1000x.py::test_1000x_reads 0.6354055246163491 iter/sec (stddev: 0.07361013504256989) 0.8381195242511715 iter/sec (stddev: 0.04240394140227035) 1.32
benchmarks/test_1000x.py::test_1000x_writes 0.6168888362878474 iter/sec (stddev: 0.07740781188601659) 0.8626650008455868 iter/sec (stddev: 0.05153168408309042) 1.40
benchmarks/test_standard.py::test_standard 0.5659124639284611 iter/sec (stddev: 0.16810369605590533) 0.7465173870618954 iter/sec (stddev: 0.1502009356924296) 1.32

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.