Skip test_lazy when html.parser is already imported#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_lazyasserts thathtml.parser/HTMLParseris not already imported so it can prove lazy loading viasix.moves.html_parser. Environments that import Django (or otherwise preloadhtml.parser) fail that precondition.This skips the test when the module is already present, matching the existing optional-module skip style in
test_six.py.Fixes #335
Test plan
pytest test_six.py::test_lazy→ passhtml.parser: same test → skippytest test_six.py→ 198 passed, 2 skipped