Merge pull request #6285 from earonesty/patch-1
Add _pytest.fixtures.FixtureLookupError to top level import
This commit is contained in:
commit
19c243f0fa
1
AUTHORS
1
AUTHORS
|
@ -94,6 +94,7 @@ Elizaveta Shashkova
|
||||||
Endre Galaczi
|
Endre Galaczi
|
||||||
Eric Hunsberger
|
Eric Hunsberger
|
||||||
Eric Siegerman
|
Eric Siegerman
|
||||||
|
Erik Aronesty
|
||||||
Erik M. Bray
|
Erik M. Bray
|
||||||
Evan Kepner
|
Evan Kepner
|
||||||
Fabien Zarifian
|
Fabien Zarifian
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Exposed the `pytest.FixtureLookupError` exception which is raised by `request.getfixturevalue()`
|
||||||
|
(where `request` is a `FixtureRequest` fixture) when a fixture with the given name cannot be returned.
|
|
@ -482,6 +482,9 @@ class FixtureRequest:
|
||||||
But if you can only decide whether to use another fixture at test
|
But if you can only decide whether to use another fixture at test
|
||||||
setup time, you may use this function to retrieve it inside a fixture
|
setup time, you may use this function to retrieve it inside a fixture
|
||||||
or test function body.
|
or test function body.
|
||||||
|
|
||||||
|
:raise pytest.FixtureLookupError:
|
||||||
|
If the given fixture could not be found.
|
||||||
"""
|
"""
|
||||||
return self._get_active_fixturedef(argname).cached_result[0]
|
return self._get_active_fixturedef(argname).cached_result[0]
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from _pytest.config import UsageError
|
||||||
from _pytest.debugging import pytestPDB as __pytestPDB
|
from _pytest.debugging import pytestPDB as __pytestPDB
|
||||||
from _pytest.fixtures import fillfixtures as _fillfuncargs
|
from _pytest.fixtures import fillfixtures as _fillfuncargs
|
||||||
from _pytest.fixtures import fixture
|
from _pytest.fixtures import fixture
|
||||||
|
from _pytest.fixtures import FixtureLookupError
|
||||||
from _pytest.fixtures import yield_fixture
|
from _pytest.fixtures import yield_fixture
|
||||||
from _pytest.freeze_support import freeze_includes
|
from _pytest.freeze_support import freeze_includes
|
||||||
from _pytest.main import Session
|
from _pytest.main import Session
|
||||||
|
@ -62,6 +63,7 @@ __all__ = [
|
||||||
"fail",
|
"fail",
|
||||||
"File",
|
"File",
|
||||||
"fixture",
|
"fixture",
|
||||||
|
"FixtureLookupError",
|
||||||
"freeze_includes",
|
"freeze_includes",
|
||||||
"Function",
|
"Function",
|
||||||
"hookimpl",
|
"hookimpl",
|
||||||
|
|
|
@ -3,5 +3,5 @@ import pytest
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def arg1(request):
|
def arg1(request):
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(pytest.FixtureLookupError):
|
||||||
request.getfixturevalue("arg2")
|
request.getfixturevalue("arg2")
|
||||||
|
|
|
@ -3,7 +3,6 @@ import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest import fixtures
|
from _pytest import fixtures
|
||||||
from _pytest.fixtures import FixtureLookupError
|
|
||||||
from _pytest.fixtures import FixtureRequest
|
from _pytest.fixtures import FixtureRequest
|
||||||
from _pytest.pathlib import Path
|
from _pytest.pathlib import Path
|
||||||
from _pytest.pytester import get_public_names
|
from _pytest.pytester import get_public_names
|
||||||
|
@ -654,7 +653,7 @@ class TestRequestBasic:
|
||||||
)
|
)
|
||||||
req = item._request
|
req = item._request
|
||||||
|
|
||||||
with pytest.raises(FixtureLookupError):
|
with pytest.raises(pytest.FixtureLookupError):
|
||||||
req.getfixturevalue("notexists")
|
req.getfixturevalue("notexists")
|
||||||
val = req.getfixturevalue("something")
|
val = req.getfixturevalue("something")
|
||||||
assert val == 1
|
assert val == 1
|
||||||
|
|
Loading…
Reference in New Issue