Fix non-sensical error message (#9077)
* Fix non-sensical error message
Introduced in 12de92cd2b
/ #7698
* Add a test
* Put the unit back into unittest
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
037d2903be
commit
112204cf8d
|
@ -0,0 +1 @@
|
|||
Fixed confusing error message when ``request.fspath`` / ``request.path`` was accessed from a session-scoped fixture.
|
|
@ -536,7 +536,7 @@ class FixtureRequest:
|
|||
@property
|
||||
def path(self) -> Path:
|
||||
if self.scope not in ("function", "class", "module", "package"):
|
||||
raise AttributeError(f"module not available in {self.scope}-scoped context")
|
||||
raise AttributeError(f"path not available in {self.scope}-scoped context")
|
||||
# TODO: Remove ignore once _pyfuncitem is properly typed.
|
||||
return self._pyfuncitem.path # type: ignore
|
||||
|
||||
|
|
|
@ -1093,6 +1093,21 @@ class TestRequestBasic:
|
|||
reprec.assertoutcome(passed=2)
|
||||
|
||||
|
||||
class TestRequestSessionScoped:
|
||||
@pytest.fixture(scope="session")
|
||||
def session_request(self, request):
|
||||
return request
|
||||
|
||||
@pytest.mark.parametrize("name", ["path", "fspath", "module"])
|
||||
def test_session_scoped_unavailable_attributes(self, session_request, name):
|
||||
expected = "path" if name == "fspath" else name
|
||||
with pytest.raises(
|
||||
AttributeError,
|
||||
match=f"{expected} not available in session-scoped context",
|
||||
):
|
||||
getattr(session_request, name)
|
||||
|
||||
|
||||
class TestRequestMarking:
|
||||
def test_applymarker(self, pytester: Pytester) -> None:
|
||||
item1, item2 = pytester.getitems(
|
||||
|
|
Loading…
Reference in New Issue