Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/pkgcheck/checks/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,21 @@ def desc(self):
)


class RedundantPyTestDisablePluginAutoload(results.LineResult, results.Warning):
"""Redundant ``PYTEST_DISABLE_PLUGIN_AUTOLOAD``

The package uses ``EPYTEST_PLUGINS`` to disable plugin autoloading already,
so ``PYTEST_DISABLE_PLUGIN_AUTOLOAD`` is redundant.
"""

@property
def desc(self):
return (
f"line {self.lineno}: PYTEST_DISABLE_PLUGIN_AUTOLOAD is redundant, "
"autoloading disabled via EPYTEST_PLUGINS already"
)


class PythonCheck(Check):
"""Python eclass checks.

Expand All @@ -302,6 +317,7 @@ class PythonCheck(Check):
PythonMissingSCMDependency,
MisplacedEPyTestVar,
ShadowedEPyTestTimeout,
RedundantPyTestDisablePluginAutoload,
}
)

Expand Down Expand Up @@ -472,12 +488,34 @@ def check_epytest_vars(self, pkg):
line = pkg.node_str(var_node)
yield MisplacedEPyTestVar(var_name, line=line, lineno=lineno + 1, pkg=pkg)

have_epytest_plugins = False
have_epytest_plugin_autoload = False
found_pytest_disable_plugin_autoload = []

for var_node in bash.var_assign_query.captures(pkg.tree.root_node).get("assign", ()):
var_name = pkg.node_str(var_node.child_by_field_name("name"))
if var_name == "EPYTEST_TIMEOUT":
lineno, _ = var_node.start_point
line = pkg.node_str(var_node)
yield ShadowedEPyTestTimeout(line=line, lineno=lineno + 1, pkg=pkg)
elif var_name == "EPYTEST_PLUGINS":
have_epytest_plugins = True
elif var_name == "EPYTEST_PLUGIN_AUTOLOAD":
if value_node := var_node.child_by_field_name("value"):
value = pkg.node_str(value_node)
if value not in ('""', "''"):
have_epytest_plugin_autoload = True
elif var_name == "PYTEST_DISABLE_PLUGIN_AUTOLOAD":
lineno, _ = var_node.start_point
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)

@staticmethod
def _prepare_deps(deps: str):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"__class__": "RedundantPyTestDisablePluginAutoload", "category": "PythonCheck", "package": "RedundantPyTestDisablePluginAutoload", "version": "0", "line": "PYTEST_DISABLE_PLUGIN_AUTOLOAD=1", "lineno": 18}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff '--color=auto' -Naur python/PythonCheck/RedundantPyTestDisablePluginAutoload/RedundantPyTestDisablePluginAutoload-0.ebuild fixed/PythonCheck/RedundantPyTestDisablePluginAutoload/RedundantPyTestDisablePluginAutoload-0.ebuild
--- python/PythonCheck/RedundantPyTestDisablePluginAutoload/RedundantPyTestDisablePluginAutoload-0.ebuild 2025-07-26 07:27:39.236976885 +0200
+++ fixed/PythonCheck/RedundantPyTestDisablePluginAutoload/RedundantPyTestDisablePluginAutoload-0.ebuild 2025-07-26 07:32:32.758757644 +0200
@@ -13,8 +13,3 @@
EPYTEST_PLUGINS=()

distutils_enable_tests pytest
-
-python_test() {
- local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
- epytest
-}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
EAPI=8

DISTUTILS_USE_PEP517=flit
PYTHON_COMPAT=( python3_10 )

inherit distutils-r1

DESCRIPTION="Ebuild with redundant disable-autoload"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
LICENSE="BSD"
SLOT="0"

EPYTEST_PLUGINS=()

distutils_enable_tests pytest

python_test() {
local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
epytest
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
EAPI=8

DISTUTILS_USE_PEP517=flit
PYTHON_COMPAT=( python3_10 )

inherit distutils-r1

DESCRIPTION="Ebuild with non-redundant disable-autoload"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
LICENSE="BSD"
SLOT="0"

EPYTEST_PLUGINS=()
EPYTEST_PLUGIN_AUTOLOAD=1

distutils_enable_tests pytest

python_test() {
epytest test_one.py

local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
epytest test_two.py
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
EAPI=8

DISTUTILS_USE_PEP517=flit
PYTHON_COMPAT=( python3_10 )

inherit distutils-r1

DESCRIPTION="Ebuild reenabling autoload"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
LICENSE="BSD"
SLOT="0"

EPYTEST_PLUGINS=()

distutils_enable_tests pytest

python_test() {
epytest test_one.py

unset PYTEST_DISABLE_PLUGIN_AUTOLOAD
epytest test_two.py
}
Loading