Skip to content

Commit

Permalink
fix: pypy
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Nov 10, 2024
1 parent 119b94b commit 68458e9
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', pypy3.8, pypy3.9, pypy3.10]
os: [ubuntu-latest, windows-latest, macos-13]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand Down
4 changes: 4 additions & 0 deletions docs/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ inline-snapshot must disable pytest assert-rewriting if you use report/review/cr
## xdist is not supported

You can not use inline-snapshot in combination with `pytest-xdist`. The use of `-n=...` implies `--inline-snapshot=disable`.

## works only with cpython

inline-snapshot works currently only with cpython. `--inline-snapshot=disable` is enforced for every other implementation.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ dependencies=["cogapp","lxml","requests"]
scripts.update="cog -r docs/**.md"

[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8"]
python = ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8","pypy3.8","pypy3.9","pypy3.10"]

[tool.hatch.envs.hatch-test]
extra-dependencies = [
Expand All @@ -114,7 +114,7 @@ extra-dependencies = [
"mypy>=1.2.0",
"pyright>=1.1.359",
"pytest-subtests>=0.11.0",
"time-machine>=2.10.0",
"pytest-freezer>=0.4.8",
"pydantic"
]
env-vars.TOP = "{root}"
Expand Down
14 changes: 13 additions & 1 deletion src/inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def xdist_running(config):
)


def is_implementation_supported():
return sys.implementation.name == "cpython"


def pytest_configure(config):
global flags

Expand All @@ -84,7 +88,7 @@ def pytest_configure(config):
f"--inline-snapshot=disable can not be combined with other flags ({', '.join(flags-{'disable'})})"
)

if xdist_running(config):
if xdist_running(config) or not is_implementation_supported():
_inline_snapshot._active = False

elif flags & {"review"}:
Expand Down Expand Up @@ -186,6 +190,14 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
)
return

if not is_implementation_supported():
if flags != {"disable"}:
terminalreporter.section("inline snapshot")
terminalreporter.write(
f"INFO: inline-snapshot was disabled because {sys.implementation.name} is not supported\n"
)
return

if not _inline_snapshot._active:
return

Expand Down
2 changes: 1 addition & 1 deletion src/inline_snapshot/testing/_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def run_pytest(
report_str = report_str.replace("\r", "")
report_str = report_str.replace(" \n", " ⏎\n")

assert report_str == report
assert report_str == report, repr(report_str)

if changed_files is not None:
current_files = {}
Expand Down
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
import re
import shutil
import sys
import textwrap
import traceback
from dataclasses import dataclass
Expand Down Expand Up @@ -30,6 +31,17 @@
black.files.find_project_root = black.files.find_project_root.__wrapped__ # type: ignore


@pytest.fixture(autouse=True)
def check_pypy(request):
implementation = sys.implementation.name
node = request.node

if implementation != "cpython" and node.get_closest_marker("no_rewriting") is None:
pytest.skip(f"{implementation} is not supported")

yield


@pytest.fixture()
def check_update(source):
def w(source_code, *, flags="", reported_flags=None, number=1):
Expand Down Expand Up @@ -268,8 +280,8 @@ def setup(self, source: str):
import pytest
@pytest.fixture(autouse=True)
def set_time(time_machine):
time_machine.move_to(datetime.datetime(2024, 3, 14, 0, 0, 0, 0),tick=False)
def set_time(freezer):
freezer.move_to(datetime.datetime(2024, 3, 14, 0, 0, 0, 0))
yield
"""
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_inline_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
from inline_snapshot.testing._example import snapshot_env


@pytest.mark.no_rewriting
def test_snapshot_eq():
with snapshot_env():
assert 1 == snapshot(1)
assert snapshot(1) == 1


@pytest.mark.no_rewriting
def test_disabled():
with snapshot_env():
_inline_snapshot._active = False
Expand Down
40 changes: 40 additions & 0 deletions tests/test_pypy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys

import pytest
from inline_snapshot import snapshot
from inline_snapshot.testing import Example


@pytest.mark.no_rewriting
def test_pypy():
report = (
snapshot("INFO: inline-snapshot was disabled because pypy is not supported")
if sys.implementation.name == "pypy"
else snapshot(
"""\
-------------------------------- Fix snapshots ---------------------------------
+----------------------------- test_something.py ------------------------------+
| @@ -1,6 +1,6 @@ |
| |
| from inline_snapshot import snapshot |
| |
| def test_example(): |
| - assert 1+1==snapshot(3) |
| + assert 1+1==snapshot(2) |
+------------------------------------------------------------------------------+
These changes will be applied, because you used --inline-snapshot=fix\
"""
)
)

Example(
"""\
from inline_snapshot import snapshot
def test_example():
assert 1+1==snapshot(3)
"""
).run_pytest(["--inline-snapshot=fix"], report=report).run_pytest(
["--inline-snapshot=disabled"], report=""
)
3 changes: 3 additions & 0 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from inline_snapshot import snapshot
from inline_snapshot.testing import Example

Expand Down Expand Up @@ -249,6 +250,7 @@ def test_a():
)


@pytest.mark.no_rewriting
def test_disable_option(project):
project.setup(
"""\
Expand Down Expand Up @@ -474,6 +476,7 @@ def test_assertion_error(project):
)


@pytest.mark.no_rewriting
def test_run_without_pytest(pytester):
# snapshots are deactivated by default
pytester.makepyfile(
Expand Down

0 comments on commit 68458e9

Please sign in to comment.