Skip to content

Commit b937c52

Browse files
committed
PythonCheck: suggest opportunities for EPYTEST_PLUGINS
Signed-off-by: Michał Górny <[email protected]>
1 parent eb95e06 commit b937c52

File tree

9 files changed

+96
-8
lines changed

9 files changed

+96
-8
lines changed

src/pkgcheck/checks/python.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ def desc(self):
294294
)
295295

296296

297+
class EPyTestPluginsSuggestion(results.VersionResult, results.Info):
298+
"""``EPYTEST_PLUGINS`` can be used to control plugins
299+
300+
The package could benefit from using ``EPYTEST_PLUGINS`` to specify
301+
pytest plugins to be loaded.
302+
"""
303+
304+
@property
305+
def desc(self):
306+
return "EPYTEST_PLUGINS can be used to control pytest plugins loaded"
307+
308+
297309
class PythonCheck(Check):
298310
"""Python eclass checks.
299311
@@ -318,6 +330,7 @@ class PythonCheck(Check):
318330
MisplacedEPyTestVar,
319331
ShadowedEPyTestTimeout,
320332
RedundantPyTestDisablePluginAutoload,
333+
EPyTestPluginsSuggestion,
321334
}
322335
)
323336

@@ -510,12 +523,15 @@ def check_epytest_vars(self, pkg):
510523
line = pkg.node_str(var_node)
511524
found_pytest_disable_plugin_autoload.append((line, lineno))
512525

513-
# EAPI 9+ defaults to disabled autoloading, in earlier EAPIs EPYTEST_PLUGINS does that.
514-
if (
515-
str(pkg.eapi) not in ("7", "8") or have_epytest_plugins
516-
) and not have_epytest_plugin_autoload:
517-
for line, lineno in found_pytest_disable_plugin_autoload:
518-
yield RedundantPyTestDisablePluginAutoload(line=line, lineno=lineno + 1, pkg=pkg)
526+
if not have_epytest_plugin_autoload:
527+
# EAPI 9+ defaults to disabled autoloading, in earlier EAPIs EPYTEST_PLUGINS does that.
528+
if str(pkg.eapi) not in ("7", "8") or have_epytest_plugins:
529+
for line, lineno in found_pytest_disable_plugin_autoload:
530+
yield RedundantPyTestDisablePluginAutoload(
531+
line=line, lineno=lineno + 1, pkg=pkg
532+
)
533+
else:
534+
yield EPyTestPluginsSuggestion(pkg=pkg)
519535

520536
@staticmethod
521537
def _prepare_deps(deps: str):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"__class__": "EPyTestPluginsSuggestion", "category": "PythonCheck", "package": "EPyTestPluginsSuggestion", "version": "0"}
2+
{"__class__": "EPyTestPluginsSuggestion", "category": "PythonCheck", "package": "EPyTestPluginsSuggestion", "version": "1"}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff '--color=auto' -Naur python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild
2+
--- python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild 2025-07-26 08:47:01.430511740 +0200
3+
+++ fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild 2025-07-26 08:53:08.525943176 +0200
4+
@@ -10,4 +10,5 @@
5+
LICENSE="BSD"
6+
SLOT="0"
7+
8+
+EPYTEST_PLUGINS=()
9+
distutils_enable_tests pytest
10+
diff '--color=auto' -Naur python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild
11+
--- python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild 2025-07-26 08:46:54.907116335 +0200
12+
+++ fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild 2025-07-26 08:53:21.533505780 +0200
13+
@@ -10,9 +10,5 @@
14+
LICENSE="BSD"
15+
SLOT="0"
16+
17+
+EPYTEST_PLUGINS=()
18+
distutils_enable_tests pytest
19+
-
20+
-python_test() {
21+
- local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
22+
- epytest
23+
-}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__class__": "ShadowedEPyTestTimeout", "category": "PythonCheck", "package": "ShadowedEPyTestTimeout", "version": "0", "line": "EPYTEST_TIMEOUT=1200", "lineno": 13}
1+
{"__class__": "ShadowedEPyTestTimeout", "category": "PythonCheck", "package": "ShadowedEPyTestTimeout", "version": "0", "line": "EPYTEST_TIMEOUT=1200", "lineno": 14}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
diff '--color=auto' -Naur python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild
22
--- python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:27:01.027875233 +0200
33
+++ fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:28:01.711247010 +0200
4-
@@ -10,5 +10,5 @@
4+
@@ -10,6 +10,6 @@
55
LICENSE="BSD"
66
SLOT="0"
77

8+
EPYTEST_PLUGINS=()
89
-EPYTEST_TIMEOUT=1200
910
+: ${EPYTEST_TIMEOUT:=1200}
1011
distutils_enable_tests pytest
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
EAPI=8
2+
3+
DISTUTILS_USE_PEP517=flit
4+
PYTHON_COMPAT=( python3_10 )
5+
6+
inherit distutils-r1
7+
8+
DESCRIPTION="Ebuild with redundant disable-autoload"
9+
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
10+
LICENSE="BSD"
11+
SLOT="0"
12+
13+
distutils_enable_tests pytest
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
EAPI=8
2+
3+
DISTUTILS_USE_PEP517=flit
4+
PYTHON_COMPAT=( python3_10 )
5+
6+
inherit distutils-r1
7+
8+
DESCRIPTION="Ebuild with redundant disable-autoload"
9+
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
10+
LICENSE="BSD"
11+
SLOT="0"
12+
13+
distutils_enable_tests pytest
14+
15+
python_test() {
16+
local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
17+
epytest
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
EAPI=8
2+
3+
DISTUTILS_USE_PEP517=flit
4+
PYTHON_COMPAT=( python3_10 )
5+
6+
inherit distutils-r1
7+
8+
DESCRIPTION="Ebuild with redundant disable-autoload"
9+
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
10+
LICENSE="BSD"
11+
SLOT="0"
12+
13+
EPYTEST_PLUGIN_AUTOLOAD=1
14+
distutils_enable_tests pytest

testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ HOMEPAGE="https://github.com/pkgcore/pkgcheck"
1010
LICENSE="BSD"
1111
SLOT="0"
1212

13+
EPYTEST_PLUGINS=()
1314
EPYTEST_TIMEOUT=1200
1415
distutils_enable_tests pytest

0 commit comments

Comments
 (0)