commit: 13e1d6c5c154883093efa94eceddf757695cb75f Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sat Jul 26 06:59:24 2025 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sat Jul 26 10:06:57 2025 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=13e1d6c5
PythonCheck: suggest opportunities for EPYTEST_PLUGINS Closes: https://github.com/pkgcore/pkgcheck/pull/754 Acked-by: Arthur Zamarin <arthurzam <AT> gentoo.org> Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> src/pkgcheck/checks/python.py | 28 +++++++++++++++++----- .../EPyTestPluginsSuggestion/expected.json | 2 ++ .../PythonCheck/EPyTestPluginsSuggestion/fix.patch | 23 ++++++++++++++++++ .../ShadowedEPyTestTimeout/expected.json | 2 +- .../PythonCheck/ShadowedEPyTestTimeout/fix.patch | 3 ++- .../EPyTestPluginsSuggestion-0.ebuild} | 3 +-- .../EPyTestPluginsSuggestion-1.ebuild} | 8 +++++-- .../EPyTestPluginsSuggestion-2.ebuild} | 4 ++-- .../ShadowedEPyTestTimeout-0.ebuild | 3 ++- 9 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/pkgcheck/checks/python.py b/src/pkgcheck/checks/python.py index 9a451c11..2ba590ad 100644 --- a/src/pkgcheck/checks/python.py +++ b/src/pkgcheck/checks/python.py @@ -294,6 +294,18 @@ class RedundantPyTestDisablePluginAutoload(results.LineResult, results.Warning): ) +class EPyTestPluginsSuggestion(results.VersionResult, results.Info): + """``EPYTEST_PLUGINS`` can be used to control plugins + + The package could benefit from using ``EPYTEST_PLUGINS`` to specify + pytest plugins to be loaded. + """ + + @property + def desc(self): + return "EPYTEST_PLUGINS can be used to control pytest plugins loaded" + + class PythonCheck(Check): """Python eclass checks. @@ -318,6 +330,7 @@ class PythonCheck(Check): MisplacedEPyTestVar, ShadowedEPyTestTimeout, RedundantPyTestDisablePluginAutoload, + EPyTestPluginsSuggestion, } ) @@ -510,12 +523,15 @@ class PythonCheck(Check): line = pkg.node_str(var_node) found_pytest_disable_plugin_autoload.append((line, lineno)) - # EAPI 9+ defaults to disabled autoloading, in earlier EAPIs EPYTEST_PLUGINS does that. - if ( - str(pkg.eapi) not in ("7", "8") or have_epytest_plugins - ) and not have_epytest_plugin_autoload: - for line, lineno in found_pytest_disable_plugin_autoload: - yield RedundantPyTestDisablePluginAutoload(line=line, lineno=lineno + 1, pkg=pkg) + if not have_epytest_plugin_autoload: + # EAPI 9+ defaults to disabled autoloading, in earlier EAPIs EPYTEST_PLUGINS does that. + if str(pkg.eapi) not in ("7", "8") or have_epytest_plugins: + for line, lineno in found_pytest_disable_plugin_autoload: + yield RedundantPyTestDisablePluginAutoload( + line=line, lineno=lineno + 1, pkg=pkg + ) + else: + yield EPyTestPluginsSuggestion(pkg=pkg) @staticmethod def _prepare_deps(deps: str): diff --git a/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/expected.json b/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/expected.json new file mode 100644 index 00000000..0613c386 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/expected.json @@ -0,0 +1,2 @@ +{"__class__": "EPyTestPluginsSuggestion", "category": "PythonCheck", "package": "EPyTestPluginsSuggestion", "version": "0"} +{"__class__": "EPyTestPluginsSuggestion", "category": "PythonCheck", "package": "EPyTestPluginsSuggestion", "version": "1"} diff --git a/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/fix.patch b/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/fix.patch new file mode 100644 index 00000000..121f4726 --- /dev/null +++ b/testdata/data/repos/python/PythonCheck/EPyTestPluginsSuggestion/fix.patch @@ -0,0 +1,23 @@ +diff '--color=auto' -Naur python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild +--- python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild 2025-07-26 08:47:01.430511740 +0200 ++++ fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild 2025-07-26 08:53:08.525943176 +0200 +@@ -10,4 +10,5 @@ + LICENSE="BSD" + SLOT="0" + ++EPYTEST_PLUGINS=() + distutils_enable_tests pytest +diff '--color=auto' -Naur python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild +--- python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild 2025-07-26 08:46:54.907116335 +0200 ++++ fixed/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild 2025-07-26 08:53:21.533505780 +0200 +@@ -10,9 +10,5 @@ + LICENSE="BSD" + SLOT="0" + ++EPYTEST_PLUGINS=() + distutils_enable_tests pytest +- +-python_test() { +- local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 +- epytest +-} diff --git a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json index a0d98f8a..1fbda2cb 100644 --- a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json +++ b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/expected.json @@ -1 +1 @@ -{"__class__": "ShadowedEPyTestTimeout", "category": "PythonCheck", "package": "ShadowedEPyTestTimeout", "version": "0", "line": "EPYTEST_TIMEOUT=1200", "lineno": 13} +{"__class__": "ShadowedEPyTestTimeout", "category": "PythonCheck", "package": "ShadowedEPyTestTimeout", "version": "0", "line": "EPYTEST_TIMEOUT=1200", "lineno": 14} diff --git a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch index 83dea272..bf028e44 100644 --- a/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch +++ b/testdata/data/repos/python/PythonCheck/ShadowedEPyTestTimeout/fix.patch @@ -1,10 +1,11 @@ diff '--color=auto' -Naur python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild --- python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:27:01.027875233 +0200 +++ fixed/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild 2025-07-12 17:28:01.711247010 +0200 -@@ -10,5 +10,5 @@ +@@ -10,6 +10,6 @@ LICENSE="BSD" SLOT="0" + EPYTEST_PLUGINS=() -EPYTEST_TIMEOUT=1200 +: ${EPYTEST_TIMEOUT:=1200} distutils_enable_tests pytest diff --git a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild similarity index 72% copy from testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild copy to testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild index c87fee5a..c314e654 100644 --- a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild +++ b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-0.ebuild @@ -5,10 +5,9 @@ PYTHON_COMPAT=( python3_10 ) inherit distutils-r1 -DESCRIPTION="Ebuild with misplaced EPYTEST vars" +DESCRIPTION="Ebuild without EPYTEST_PLUGINS" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" SLOT="0" -EPYTEST_TIMEOUT=1200 distutils_enable_tests pytest diff --git a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild similarity index 60% copy from testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild copy to testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild index c87fee5a..197bd3d0 100644 --- a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild +++ b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-1.ebuild @@ -5,10 +5,14 @@ PYTHON_COMPAT=( python3_10 ) inherit distutils-r1 -DESCRIPTION="Ebuild with misplaced EPYTEST vars" +DESCRIPTION="Ebuild with old-style autoload-disable" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" SLOT="0" -EPYTEST_TIMEOUT=1200 distutils_enable_tests pytest + +python_test() { + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 + epytest +} diff --git a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-2.ebuild similarity index 72% copy from testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild copy to testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-2.ebuild index c87fee5a..5c422255 100644 --- a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild +++ b/testdata/repos/python/PythonCheck/EPyTestPluginsSuggestion/EPyTestPluginsSuggestion-2.ebuild @@ -5,10 +5,10 @@ PYTHON_COMPAT=( python3_10 ) inherit distutils-r1 -DESCRIPTION="Ebuild with misplaced EPYTEST vars" +DESCRIPTION="Ebuild with explicit autoload" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" SLOT="0" -EPYTEST_TIMEOUT=1200 +EPYTEST_PLUGIN_AUTOLOAD=1 distutils_enable_tests pytest diff --git a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild b/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild index c87fee5a..c0676588 100644 --- a/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild +++ b/testdata/repos/python/PythonCheck/ShadowedEPyTestTimeout/ShadowedEPyTestTimeout-0.ebuild @@ -5,10 +5,11 @@ PYTHON_COMPAT=( python3_10 ) inherit distutils-r1 -DESCRIPTION="Ebuild with misplaced EPYTEST vars" +DESCRIPTION="Ebuild with shadowed EPYTEST_TIMEOUT" HOMEPAGE="https://github.com/pkgcore/pkgcheck" LICENSE="BSD" SLOT="0" +EPYTEST_PLUGINS=() EPYTEST_TIMEOUT=1200 distutils_enable_tests pytest
