Skip to content

Commit

Permalink
Support pytest 7
Browse files Browse the repository at this point in the history
Fixes #2704
  • Loading branch information
hroncok committed Dec 17, 2021
1 parent 61fe841 commit 53d6683
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions tests/optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from typing import FrozenSet, List, Set, TYPE_CHECKING

import pytest
from _pytest.store import StoreKey

try:
from pytest import StashKey
except ImportError:
# pytest < 7
from _pytest.store import StoreKey as StashKey

log = logging.getLogger(__name__)

Expand All @@ -33,8 +38,8 @@
from _pytest.nodes import Node


ALL_POSSIBLE_OPTIONAL_MARKERS = StoreKey[FrozenSet[str]]()
ENABLED_OPTIONAL_MARKERS = StoreKey[FrozenSet[str]]()
ALL_POSSIBLE_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()
ENABLED_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()


def pytest_addoption(parser: "Parser") -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_no_ipynb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
import os
import pathlib

from tests.util import THIS_DIR
from black import main, jupyter_dependencies_are_installed
from click.testing import CliRunner
from _pytest.tmpdir import tmpdir

pytestmark = pytest.mark.no_jupyter

Expand All @@ -22,14 +22,14 @@ def test_ipynb_diff_with_no_change_single() -> None:
assert expected_output in result.output


def test_ipynb_diff_with_no_change_dir(tmpdir: tmpdir) -> None:
def test_ipynb_diff_with_no_change_dir(tmp_path: pathlib.Path) -> None:
jupyter_dependencies_are_installed.cache_clear()
runner = CliRunner()
nb = os.path.join("tests", "data", "notebook_trailing_newline.ipynb")
tmp_nb = tmpdir / "notebook.ipynb"
tmp_nb = tmp_path / "notebook.ipynb"
with open(nb) as src, open(tmp_nb, "w") as dst:
dst.write(src.read())
result = runner.invoke(main, [str(tmpdir)])
result = runner.invoke(main, [str(tmp_path)])
expected_output = (
"Skipping .ipynb files as Jupyter dependencies are not installed.\n"
"You can fix this by running ``pip install black[jupyter]``\n"
Expand Down

0 comments on commit 53d6683

Please sign in to comment.