Merge pull request #6285 from earonesty/patch-1

Add _pytest.fixtures.FixtureLookupError to top level import
This commit is contained in:
Ronny Pfannschmidt 2020-04-10 07:58:58 +02:00 committed by GitHub
commit 19c243f0fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 3 deletions

View File

@ -94,6 +94,7 @@ Elizaveta Shashkova
Endre Galaczi
Eric Hunsberger
Eric Siegerman
Erik Aronesty
Erik M. Bray
Evan Kepner
Fabien Zarifian

View File

@ -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.

View File

@ -482,6 +482,9 @@ class FixtureRequest:
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
or test function body.
:raise pytest.FixtureLookupError:
If the given fixture could not be found.
"""
return self._get_active_fixturedef(argname).cached_result[0]

View File

@ -14,6 +14,7 @@ from _pytest.config import UsageError
from _pytest.debugging import pytestPDB as __pytestPDB
from _pytest.fixtures import fillfixtures as _fillfuncargs
from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureLookupError
from _pytest.fixtures import yield_fixture
from _pytest.freeze_support import freeze_includes
from _pytest.main import Session
@ -62,6 +63,7 @@ __all__ = [
"fail",
"File",
"fixture",
"FixtureLookupError",
"freeze_includes",
"Function",
"hookimpl",

View File

@ -3,5 +3,5 @@ import pytest
@pytest.fixture
def arg1(request):
with pytest.raises(Exception):
with pytest.raises(pytest.FixtureLookupError):
request.getfixturevalue("arg2")

View File

@ -3,7 +3,6 @@ import textwrap
import pytest
from _pytest import fixtures
from _pytest.fixtures import FixtureLookupError
from _pytest.fixtures import FixtureRequest
from _pytest.pathlib import Path
from _pytest.pytester import get_public_names
@ -654,7 +653,7 @@ class TestRequestBasic:
)
req = item._request
with pytest.raises(FixtureLookupError):
with pytest.raises(pytest.FixtureLookupError):
req.getfixturevalue("notexists")
val = req.getfixturevalue("something")
assert val == 1