Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 835163 - python-utils-r1.eclass: epytest should set PYTEST_DISABLE_PLUGIN_AUTOLOAD
Summary: python-utils-r1.eclass: epytest should set PYTEST_DISABLE_PLUGIN_AUTOLOAD
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-14 23:19 UTC by Matt Whitlock
Modified: 2022-04-04 18:57 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Whitlock 2022-03-14 23:19:13 UTC
As was discovered in Bug 661218, the mere presence of the pytest-relaxed plugin on the system would break unit tests of packages that were not intended to be used with it. I recently ran into similar issues with the pytest-twisted plugin.

Back in 2018, at the request of Gentoo developer Virgil Dupras, Pytest upstream implemented an option to disable autoloading of plugins entirely:

  https://github.com/pytest-dev/pytest/issues/3784

However, this was apparently never followed up on, as the epytest function in python-utils-r1.eclass only disables a select few plugins explicitly and does not make use of the option that was implemented for us.

Please make epytest set PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 while running Pytest. This should mean that "-p no:cov -p no:flake8 -p no:flakes -p no:pylint" no longer need to be specified, as all plugins will be disabled by default.

Note that this change *will* break the tests in many ebuilds, which will now need to explicitly specify their pytest plugins rather than relying on autoloading of whatever plugins happen to be installed on the system. As such, I do not make this request lightly, but I do believe it is in the best interest of all Gentoo Python developers and users to reduce environment variability when running unit tests of Python packages. Switching to explicit specification of required Pytest plugins seems like a win in the long run.
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-03-14 23:24:38 UTC
I thought I'd remembered mgorny exploring this but maybe not (might be thinking of https://github.com/gentoo/gentoo/commit/f10588909c89639ce3a68ed2bcff6d7b05da1ba8, which just disables some plugins).
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-03-15 08:52:41 UTC
I've been thinking about this in the past but I think the breakage is too large.  I mean, figuring out all the test failures and finding the right set of plugins is a huge undertaking.  It doesn't help that usually the resulting failures and errors are far from explanatory.

It doesn't help that some packages use some plugins optionally but don't check correctly for them.  For example, they enable xdist-related code if 'import xdist' works, which causes the package to explode when xdist plugin is not actually loaded.
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-03-15 08:52:56 UTC
(if at all, it can only happen in a new EAPI)
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-03-15 08:53:41 UTC
Finally, there's the problem of indirect pytest tests that would be affected by the envvar but can't be trivially fixed to load the right set of plugins.
Comment 5 Matt Whitlock 2022-03-15 16:08:47 UTC
All good points. Thank you for your consideration.

Perhaps just recommend setting the envvar as a best practice in your Python development guide, although you're right that the errors that result from not having a plugin loaded when it's needed (and also having a plugin loaded when it's not expected!) are far from explanatory. In my case, the autoloading of the pytest-twisted plugin was breaking dynamic class method dispatch in the python-bitcointx library, a totally non-obvious and perplexing side effect.