-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
911b7a0
commit 6d8f700
Showing
3 changed files
with
61 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from pathlib import Path | ||
# Python<=3.8 don't support typing with builtin dict. | ||
from typing import Dict | ||
|
||
import pytest | ||
|
||
PYTEST_VER = tuple(int(x) for x in pytest.__version__.split(".")[:2]) | ||
|
||
try: | ||
from pytest import Stash, StashKey | ||
except ImportError: | ||
from _pytest.store import Store as Stash, StoreKey as StashKey | ||
|
||
|
||
_MTIMES_STASH_KEY = StashKey[Dict[str, float]]() | ||
|
||
|
||
def make_path_kwargs(p): | ||
""" | ||
Make keyword arguments passing either path or fspath, depending on pytest version. | ||
In pytest 7.0, the `fspath` argument to Nodes has been deprecated, so we pass `path` | ||
instead. | ||
""" | ||
return dict(path=Path(p)) if PYTEST_VER >= (7, 0) else dict(fspath=p) | ||
|
||
|
||
def get_stash_object(config): | ||
try: | ||
stash = config.stash | ||
except AttributeError: | ||
stash = config._store | ||
return stash | ||
|
||
|
||
def get_stash(config): | ||
missing = object() | ||
stash = get_stash_object(config).get(_MTIMES_STASH_KEY, default=missing) | ||
assert stash is not missing | ||
return stash | ||
|
||
|
||
def set_stash(config, value): | ||
get_stash_object(config)[_MTIMES_STASH_KEY] = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters