Skip to content

Commit

Permalink
Fix pytest without cache -pno:cacheprovider (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio authored Jul 21, 2024
1 parent 759cacd commit 0a0794e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
7 changes: 2 additions & 5 deletions pytest_ruff/_pytest_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

try:
from pytest import Stash, StashKey
from pytest import Stash as Stash, StashKey
except ImportError:
import _pytest.store

Expand Down Expand Up @@ -36,10 +36,7 @@ def get_stash_object(config):


def get_stash(config):
missing = object()
stash = get_stash_object(config).get(_MTIMES_STASH_KEY, default=missing)
assert stash is not missing
return stash
return get_stash_object(config).get(_MTIMES_STASH_KEY, default=None)


def set_stash(config, value):
Expand Down
File renamed without changes.
File renamed without changes.
Empty file added tests/assets/ok.py
Empty file.
20 changes: 19 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,29 @@ def test_broken_ruff_config():
"-m",
"pytest",
"--ruff",
"tests/assets/broken_config/empty.py",
"tests/assets/config_broken/empty.py",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = process.communicate()
assert err.decode() == ""
assert "unknown field `broken`" in out.decode()


def test_without_pytest_cache():
process = subprocess.Popen(
[
sys.executable,
"-m",
"pytest",
"--ruff",
"-pno:cacheprovider",
"tests/assets/ok.py",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, err = process.communicate()
assert err.decode() == ""
assert "tests/assets/ok.py ." in out.decode()
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = py{38,39,310,311,312}-pytest{5,6,7,8,810,81},lint
envlist = py{38,39,310,311,312}-pytest{5,6,7,8,810,latest},lint

[testenv]
allowlist_externals = poetry
Expand All @@ -9,10 +9,10 @@ commands =
pytest5: pip install "pytest<6"
pytest6: pip install "pytest>=6,<7"
pytest7: pip install "pytest>=7,<8"
pytest8: pip install "pytest>=8,<8.1"
pytest8: pip install "pytest>=8,<9"
# pytest 8.1.0 was yanked, but their "broken behaviour" will comeback soon
pytest810: pip install "pytest==8.1.0"
pytest81: pip install "pytest>=8.1,<9"
pytestlatest: pip install pytest
# Disable ruff plugin to generate better coverage results
poetry run pytest -p no:ruff -vvv --cov --cov-append --cov-report term --cov-report xml {posargs}

Expand Down

0 comments on commit 0a0794e

Please sign in to comment.