test: disable pytest plugin autoload under tox#405
Conversation
Django and similar packages import html.parser at startup, which makes the lazy-load pre-condition of test_lazy impossible. Skip in that case instead of failing the suite. Fixes benjaminp#335 Signed-off-by: Alex Chen <l46983284@gmail.com>
|
Why would Django be imported in the six test suite? |
The six suite does not import Django. Skip only when the lazy-load pre-condition is already broken because html.parser/HTMLParser is present in sys.modules from the surrounding environment. Signed-off-by: Alex Chen <l46983284@gmail.com>
|
It wouldn't. six doesn't import Django. Issue #335 is about running the suite in an environment where Django (or anything else) has already imported |
|
Why does django get loaded into six's test process though? |
six does not import Django. When Django is installed and an ambient pytest plugin imports it at collection time (hypothesis.internal.compat -> django.test -> django.utils.html), html.parser is already in sys.modules and the lazy-load pre-condition cannot hold. Skip in that case; keep the test when the process is clean. Signed-off-by: Alex Chen <l46983284@gmail.com>
|
It is not six that loads Django. On issue #335 the pytest banner shows ambient plugins, including hypothesis. When Django is also installed in that environment, importing the hypothesis pytest plugin pulls Controls I ran:
So the failure mode is polluted site-packages / plugin autoload, not the six test suite importing Django. The skip is only for the broken pre-condition ( |
|
I'm not sure we can be robust about global pollution of the Python environment. I wonder if there's a way to avoid picking up arbitrary and unneeded plugins like this. |
test_lazy needs a clean process. Ambient site-packages plugins can be auto-loaded by pytest and import unrelated packages before the suite runs. Set PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 in tox (pytest-only deps) so the suite does not pick up those plugins. Restore the original pre-condition assert instead of skipping on pollution. Signed-off-by: Alex Chen <l46983284@gmail.com>
|
Good point — the failure comes from pytest auto-loading installed plugins, not from six importing anything extra. I changed the approach: I also dropped the skip-based workaround and restored the original |
Summary
test_lazyneeds a clean process so it can provesix.moves.html_parserloadshtml.parserlazily. When pytest auto-loads ambient third-party plugins, some of them can importhtml.parser(or pull in packages that do) before the test runs, so the precondition fails even though six itself is fine.This sets
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1in the tox testenv so the suite only uses pytest itself (tox already depends on pytest alone). That matches maintainer feedback: avoid picking up arbitrary installed plugins rather than special-casing every preloaded module.Also adds my name to
CONTRIBUTORS.Fixes #335
Test plan
tox -e py/python -m pytest test_six.pyunder this tox env (plugin autoload off)test_lazyno longer depends on a skip for preloadedhtml.parsertest_six.pygreen in the tox configurationNote on earlier approach
An earlier revision of this PR skipped
test_lazywhenhtml.parserwas already imported. That is no longer the product unit; the tox env var is the fix on the current head.