From b40a9f9add7c53f86bbb7b6ea1695d92b56cdb13 Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 10:53:05 -0500 Subject: [PATCH 1/9] Export FixtureLookupError to top level --- src/pytest/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 33bc3d0fb..2f63164b3 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -15,6 +15,7 @@ from _pytest.debugging import pytestPDB as __pytestPDB from _pytest.fixtures import fillfixtures as _fillfuncargs from _pytest.fixtures import fixture from _pytest.fixtures import yield_fixture +from _pytest.fixtures import FixtureLookupError from _pytest.freeze_support import freeze_includes from _pytest.main import Session from _pytest.mark import MARK_GEN as mark From 0f00495548234f9c3253a923af4bed1f244e475d Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:02:43 -0500 Subject: [PATCH 2/9] Create 6285.feature.rst --- changelog/6285.feature.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/6285.feature.rst diff --git a/changelog/6285.feature.rst b/changelog/6285.feature.rst new file mode 100644 index 000000000..74c691224 --- /dev/null +++ b/changelog/6285.feature.rst @@ -0,0 +1,2 @@ +Use `pytest.FixtureLookupError` to catch exceptions when calling `request.getfixturevalue`. + From 74cdff86f86ad8ee01b221acebd21fa61382561f Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:07:51 -0500 Subject: [PATCH 3/9] Update conftest.py --- .../sub1/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/example_scripts/fixtures/fill_fixtures/test_conftest_funcargs_only_available_in_subdir/sub1/conftest.py b/testing/example_scripts/fixtures/fill_fixtures/test_conftest_funcargs_only_available_in_subdir/sub1/conftest.py index 79af4bc47..be5adbeb6 100644 --- a/testing/example_scripts/fixtures/fill_fixtures/test_conftest_funcargs_only_available_in_subdir/sub1/conftest.py +++ b/testing/example_scripts/fixtures/fill_fixtures/test_conftest_funcargs_only_available_in_subdir/sub1/conftest.py @@ -3,5 +3,5 @@ import pytest @pytest.fixture def arg1(request): - with pytest.raises(Exception): + with pytest.raises(pytest.FixtureLookupError): request.getfixturevalue("arg2") From 7667ff51e7f3c9b2eb0b97e0e28390736163efdc Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:10:18 -0500 Subject: [PATCH 4/9] Update fixtures.py --- testing/python/fixtures.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index bfbe35951..36e55a0e1 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -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 From 615474329d9d16269b2db5f95cc46db6129e68a4 Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:12:48 -0500 Subject: [PATCH 5/9] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index af0dc62c4..99f7f8b2d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -94,6 +94,7 @@ Elizaveta Shashkova Endre Galaczi Eric Hunsberger Eric Siegerman +Erik Aronesty Erik M. Bray Evan Kepner Fabien Zarifian From 9b8ed8d9ad2cf4022ff5c0a3a6c08ea96c2856a2 Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:24:40 -0500 Subject: [PATCH 6/9] Update pytest.py --- src/pytest/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 2f63164b3..7c8d834ca 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -63,6 +63,7 @@ __all__ = [ "fail", "File", "fixture", + "FixtureLookupError", "freeze_includes", "Function", "hookimpl", From b2d54fe6b1d911349a9a2f8610e8882e48b65957 Mon Sep 17 00:00:00 2001 From: earonesty Date: Wed, 27 Nov 2019 11:28:35 -0500 Subject: [PATCH 7/9] Fix tox alpha order --- src/pytest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 7c8d834ca..ec0298d00 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -14,8 +14,8 @@ 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 yield_fixture from _pytest.fixtures import FixtureLookupError +from _pytest.fixtures import yield_fixture from _pytest.freeze_support import freeze_includes from _pytest.main import Session from _pytest.mark import MARK_GEN as mark From a03e076e892277261b73507d90cab4dc7b79ad6c Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 3 Mar 2020 09:48:46 -0300 Subject: [PATCH 8/9] Update changelog/6285.feature.rst Co-Authored-By: Ran Benita --- changelog/6285.feature.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/6285.feature.rst b/changelog/6285.feature.rst index 74c691224..bac353c86 100644 --- a/changelog/6285.feature.rst +++ b/changelog/6285.feature.rst @@ -1,2 +1,2 @@ -Use `pytest.FixtureLookupError` to catch exceptions when calling `request.getfixturevalue`. - +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. From aac11e5e75b4aef295e857a2ae96e4438f28d6b9 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 3 Mar 2020 10:05:19 -0300 Subject: [PATCH 9/9] Mention FixtureLookupError in getfixturevalue docs --- src/_pytest/fixtures.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index cdd249d93..61849b762 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -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]