From b95e85ab931565233147d541738cf4ac42fbb7c3 Mon Sep 17 00:00:00 2001 From: Jiajun Xu Date: Fri, 7 Jun 2024 23:56:55 -0400 Subject: [PATCH 01/11] warns when usefixtures is empty --- src/_pytest/fixtures.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 06da52aeda3..a01b6bfa4b5 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1525,6 +1525,8 @@ def _getautousenames(self, node: nodes.Node) -> Iterator[str]: def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: """Return the names of usefixtures fixtures applicable to node.""" for mark in node.iter_markers(name="usefixtures"): + if not mark.args: + warnings.warn(f"Warning: empty usefixtures in {node.name}.") yield from mark.args def getfixtureclosure( From 1507213d000b4837416eadb6fe455da40135f7da Mon Sep 17 00:00:00 2001 From: Jiajun Xu Date: Wed, 10 Jul 2024 13:52:34 -0400 Subject: [PATCH 02/11] Changed _getusefixturesnames to include location - Updated _getusefixturesnames to iterate with node and marker using node.iter_markers_with_node. - Modified warning message to include the location of the marker node. - Replaced warnings.warn with node.warn to issue warnings. --- src/_pytest/fixtures.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 00b86e7fcae..750605b33da 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1535,9 +1535,10 @@ def _getautousenames(self, node: nodes.Node) -> Iterator[str]: def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: """Return the names of usefixtures fixtures applicable to node.""" - for mark in node.iter_markers(name="usefixtures"): + for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: - warnings.warn(f"Warning: empty usefixtures in {node.name}.") + location = getattr(marker_node, "location", "unknown location") + node.warn(Warning(f"empty usefixtures in {node.name} from {location}.")) yield from mark.args def getfixtureclosure( From e26114519f52f87b85e4d9a919f4f1c65020605f Mon Sep 17 00:00:00 2001 From: Jiajun Xu Date: Wed, 10 Jul 2024 18:01:18 -0400 Subject: [PATCH 03/11] Updated changelog to include fixture improvement --- changelog/12426.improvement.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/12426.improvement.rst diff --git a/changelog/12426.improvement.rst b/changelog/12426.improvement.rst new file mode 100644 index 00000000000..70e0ac2ec5f --- /dev/null +++ b/changelog/12426.improvement.rst @@ -0,0 +1 @@ +A warning in now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. \ No newline at end of file From 7896d006405216e2abc7bc063e9c70fdfc60c4b2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2024 00:02:59 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelog/12426.improvement.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/12426.improvement.rst b/changelog/12426.improvement.rst index 70e0ac2ec5f..aafd26880a6 100644 --- a/changelog/12426.improvement.rst +++ b/changelog/12426.improvement.rst @@ -1 +1 @@ -A warning in now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. \ No newline at end of file +A warning in now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. From c2322b5cbf105b47ceccb8aec57ffd3827484f7f Mon Sep 17 00:00:00 2001 From: Jiajun Xu <131632195+JiajunXu2@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:24:05 -0400 Subject: [PATCH 05/11] Update 12426.improvement.rst fixed typo --- changelog/12426.improvement.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/12426.improvement.rst b/changelog/12426.improvement.rst index aafd26880a6..dbc47fa60d7 100644 --- a/changelog/12426.improvement.rst +++ b/changelog/12426.improvement.rst @@ -1 +1 @@ -A warning in now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. +A warning is now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. From b5b2e3d0ead952d111ed60c34275d17fffd37e1b Mon Sep 17 00:00:00 2001 From: Jiajun Xu <131632195+JiajunXu2@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:16:22 -0400 Subject: [PATCH 06/11] Update changelog/12426.improvement.rst Co-authored-by: Bruno Oliveira --- changelog/12426.improvement.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/12426.improvement.rst b/changelog/12426.improvement.rst index dbc47fa60d7..0da1f838aea 100644 --- a/changelog/12426.improvement.rst +++ b/changelog/12426.improvement.rst @@ -1 +1 @@ -A warning is now issued when @pytest.mark.usefixtures() is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. +A warning is now issued when :ref:`pytest.mark.usefixtures ref` is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored. From 2c74288268d918692380e9e719d7cf63676a035e Mon Sep 17 00:00:00 2001 From: Jiajun Xu <131632195+JiajunXu2@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:16:39 -0400 Subject: [PATCH 07/11] Update src/_pytest/fixtures.py Co-authored-by: Bruno Oliveira --- src/_pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 750605b33da..de83e894648 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1538,7 +1538,7 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: location = getattr(marker_node, "location", "unknown location") - node.warn(Warning(f"empty usefixtures in {node.name} from {location}.")) + node.warn(Warning(f"usefixtures() is empty, so it has no effect")) yield from mark.args def getfixtureclosure( From 3bf2639e97031a9fa78f70899d5685519091ecd7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:18:13 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index de83e894648..5beb59d0434 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1538,7 +1538,7 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: location = getattr(marker_node, "location", "unknown location") - node.warn(Warning(f"usefixtures() is empty, so it has no effect")) + node.warn(Warning("usefixtures() is empty, so it has no effect")) yield from mark.args def getfixtureclosure( From 616c7356cd7f17b9a2c95f04dab135532657704e Mon Sep 17 00:00:00 2001 From: Jiajun Xu Date: Mon, 15 Jul 2024 12:25:03 -0400 Subject: [PATCH 09/11] removed location retrieval from _getusefixturesnames --- src/_pytest/fixtures.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 750605b33da..dcf288e411c 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1537,8 +1537,7 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: """Return the names of usefixtures fixtures applicable to node.""" for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: - location = getattr(marker_node, "location", "unknown location") - node.warn(Warning(f"empty usefixtures in {node.name} from {location}.")) + node.warn(Warning(f"usefixtures() is empty, so it has no effect")) yield from mark.args def getfixtureclosure( From 05f7865d2d722496f1791b7ed6c6d542be93ac26 Mon Sep 17 00:00:00 2001 From: Jiajun Xu Date: Mon, 15 Jul 2024 12:39:14 -0400 Subject: [PATCH 10/11] Changed node.warn to marker_node.warn --- src/_pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index dcf288e411c..0df4ac57813 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1537,7 +1537,7 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: """Return the names of usefixtures fixtures applicable to node.""" for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: - node.warn(Warning(f"usefixtures() is empty, so it has no effect")) + marker_node.warn(Warning(f"usefixtures() is empty, so it has no effect")) yield from mark.args def getfixtureclosure( From d8c56e581ba11c24da6abd08bc8a1d0918b91046 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:46:36 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 0df4ac57813..52dee3d62a7 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1537,7 +1537,7 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]: """Return the names of usefixtures fixtures applicable to node.""" for marker_node, mark in node.iter_markers_with_node(name="usefixtures"): if not mark.args: - marker_node.warn(Warning(f"usefixtures() is empty, so it has no effect")) + marker_node.warn(Warning("usefixtures() is empty, so it has no effect")) yield from mark.args def getfixtureclosure(