store: rename Store to Stash
The name "stash" is a bit more distinguishable and more evocative of the intended usage.
This commit is contained in:
@@ -21,7 +21,7 @@ from _pytest.pytester import Pytester
|
||||
from _pytest.pytester import RunResult
|
||||
from _pytest.reports import BaseReport
|
||||
from _pytest.reports import TestReport
|
||||
from _pytest.store import Store
|
||||
from _pytest.stash import Stash
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@@ -951,7 +951,7 @@ def test_dont_configure_on_workers(tmp_path: Path) -> None:
|
||||
def __init__(self):
|
||||
self.pluginmanager = self
|
||||
self.option = self
|
||||
self._store = Store()
|
||||
self._store = Stash()
|
||||
|
||||
def getini(self, name):
|
||||
return "pytest"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import pytest
|
||||
from _pytest.stash import Stash
|
||||
from _pytest.stash import StashKey
|
||||
|
||||
|
||||
def test_stash() -> None:
|
||||
stash = Stash()
|
||||
|
||||
key1 = StashKey[str]()
|
||||
key2 = StashKey[int]()
|
||||
|
||||
# Basic functionality - single key.
|
||||
assert key1 not in stash
|
||||
stash[key1] = "hello"
|
||||
assert key1 in stash
|
||||
assert stash[key1] == "hello"
|
||||
assert stash.get(key1, None) == "hello"
|
||||
stash[key1] = "world"
|
||||
assert stash[key1] == "world"
|
||||
# Has correct type (no mypy error).
|
||||
stash[key1] + "string"
|
||||
|
||||
# No interaction with another key.
|
||||
assert key2 not in stash
|
||||
assert stash.get(key2, None) is None
|
||||
with pytest.raises(KeyError):
|
||||
stash[key2]
|
||||
with pytest.raises(KeyError):
|
||||
del stash[key2]
|
||||
stash[key2] = 1
|
||||
assert stash[key2] == 1
|
||||
# Has correct type (no mypy error).
|
||||
stash[key2] + 20
|
||||
del stash[key1]
|
||||
with pytest.raises(KeyError):
|
||||
del stash[key1]
|
||||
with pytest.raises(KeyError):
|
||||
stash[key1]
|
||||
|
||||
# setdefault
|
||||
stash[key1] = "existing"
|
||||
assert stash.setdefault(key1, "default") == "existing"
|
||||
assert stash[key1] == "existing"
|
||||
key_setdefault = StashKey[bytes]()
|
||||
assert stash.setdefault(key_setdefault, b"default") == b"default"
|
||||
assert stash[key_setdefault] == b"default"
|
||||
|
||||
# Can't accidentally add attributes to stash object itself.
|
||||
with pytest.raises(AttributeError):
|
||||
stash.foo = "nope" # type: ignore[attr-defined]
|
||||
|
||||
# No interaction with anoter stash.
|
||||
stash2 = Stash()
|
||||
key3 = StashKey[int]()
|
||||
assert key2 not in stash2
|
||||
stash2[key2] = 100
|
||||
stash2[key3] = 200
|
||||
assert stash2[key2] + stash2[key3] == 300
|
||||
assert stash[key2] == 1
|
||||
assert key3 not in stash
|
||||
@@ -1,60 +0,0 @@
|
||||
import pytest
|
||||
from _pytest.store import Store
|
||||
from _pytest.store import StoreKey
|
||||
|
||||
|
||||
def test_store() -> None:
|
||||
store = Store()
|
||||
|
||||
key1 = StoreKey[str]()
|
||||
key2 = StoreKey[int]()
|
||||
|
||||
# Basic functionality - single key.
|
||||
assert key1 not in store
|
||||
store[key1] = "hello"
|
||||
assert key1 in store
|
||||
assert store[key1] == "hello"
|
||||
assert store.get(key1, None) == "hello"
|
||||
store[key1] = "world"
|
||||
assert store[key1] == "world"
|
||||
# Has correct type (no mypy error).
|
||||
store[key1] + "string"
|
||||
|
||||
# No interaction with another key.
|
||||
assert key2 not in store
|
||||
assert store.get(key2, None) is None
|
||||
with pytest.raises(KeyError):
|
||||
store[key2]
|
||||
with pytest.raises(KeyError):
|
||||
del store[key2]
|
||||
store[key2] = 1
|
||||
assert store[key2] == 1
|
||||
# Has correct type (no mypy error).
|
||||
store[key2] + 20
|
||||
del store[key1]
|
||||
with pytest.raises(KeyError):
|
||||
del store[key1]
|
||||
with pytest.raises(KeyError):
|
||||
store[key1]
|
||||
|
||||
# setdefault
|
||||
store[key1] = "existing"
|
||||
assert store.setdefault(key1, "default") == "existing"
|
||||
assert store[key1] == "existing"
|
||||
key_setdefault = StoreKey[bytes]()
|
||||
assert store.setdefault(key_setdefault, b"default") == b"default"
|
||||
assert store[key_setdefault] == b"default"
|
||||
|
||||
# Can't accidentally add attributes to store object itself.
|
||||
with pytest.raises(AttributeError):
|
||||
store.foo = "nope" # type: ignore[attr-defined]
|
||||
|
||||
# No interaction with anoter store.
|
||||
store2 = Store()
|
||||
key3 = StoreKey[int]()
|
||||
assert key2 not in store2
|
||||
store2[key2] = 100
|
||||
store2[key3] = 200
|
||||
assert store2[key2] + store2[key3] == 300
|
||||
assert store[key2] == 1
|
||||
assert key3 not in store
|
||||
Reference in New Issue
Block a user