From 85cc12e3284e2ad6126fd9c7adb69fcaf1b9be3b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 30 Jun 2019 12:58:50 -0300 Subject: [PATCH] Move FIXTURE_FUNCTION_CALL constant to the point of error This is no longer a deprecation so it makes sense to move it to the place where it is needed instead of leaving it in deprecated.py --- src/_pytest/deprecated.py | 7 ------- src/_pytest/fixtures.py | 10 ++++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 3d3f73a60..39c8c23cd 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -19,13 +19,6 @@ DEPRECATED_EXTERNAL_PLUGINS = { } -FIXTURE_FUNCTION_CALL = ( - 'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n' - "but are created automatically when test functions request them as parameters.\n" - "See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and\n" - "https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code." -) - FIXTURE_NAMED_REQUEST = PytestDeprecationWarning( "'request' is a reserved name for fixtures and will raise an error in future versions" ) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 2cde5725c..9a385fc42 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -26,7 +26,6 @@ from _pytest.compat import getlocation from _pytest.compat import is_generator from _pytest.compat import NOTSET from _pytest.compat import safe_getattr -from _pytest.deprecated import FIXTURE_FUNCTION_CALL from _pytest.deprecated import FIXTURE_NAMED_REQUEST from _pytest.outcomes import fail from _pytest.outcomes import TEST_OUTCOME @@ -933,9 +932,12 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker): """Wrap the given fixture function so we can raise an error about it being called directly, instead of used as an argument in a test function. """ - message = FIXTURE_FUNCTION_CALL.format( - name=fixture_marker.name or function.__name__ - ) + message = ( + 'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n' + "but are created automatically when test functions request them as parameters.\n" + "See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and\n" + "https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code." + ).format(name=fixture_marker.name or function.__name__) @functools.wraps(function) def result(*args, **kwargs):