test_ok2/testing
Bruno Oliveira c85fce39b6 Change importlib to first try to import modules using the standard mechanism
As detailed in
https://github.com/pytest-dev/pytest/issues/11475#issuecomment-1937043670,
currently with `--import-mode=importlib` pytest will try to import every
file by using a unique module name, regardless if that module could be
imported using the normal import mechanism without touching `sys.path`.

This has the consequence that non-test modules available in `sys.path`
(via other mechanism, such as being installed into a virtualenv,
PYTHONPATH, etc) would end up being imported as standalone modules,
instead of imported with their expected module names.

To illustrate:

```
.env/
  lib/
    site-packages/
      anndata/
        core.py
```

Given `anndata` is installed into the virtual environment, `python -c
"import anndata.core"` works, but pytest with `importlib` mode would
import that module as a standalone module named
`".env.lib.site-packages.anndata.core"`, because importlib module was
designed to import test files which are not reachable from `sys.path`,
but now it is clear that normal modules should be imported using the
standard mechanisms if possible.

Now `imporlib` mode will first try to import the module normally,
without changing `sys.path`, and if that fails it falls back to
importing the module as a standalone module.

This also makes `importlib` respect namespace packages.

This supersedes #11931.

Fix #11475
Close #11931
2024-03-02 16:13:48 -03:00
..
_py [flake8-bugbear] Fix all the useless expressions that are justified 2024-02-04 19:27:23 +01:00
code [flake8-bugbear] Fix all the useless expressions that are justified 2024-02-04 19:27:23 +01:00
example_scripts Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
examples fix bug in test for issue 519 2021-03-07 15:01:39 +01:00
freeze [ruff] Fix all consider [*cats, garfield] instead of cats + [garfield] 2024-02-02 15:18:38 +01:00
io [ruff] Fix ambiguous characters found in string and comment 2024-02-02 15:18:38 +01:00
logging Add --log-file-mode option to the logging plugin, enabling appending to log-files (#11979) 2024-02-21 12:02:19 +00:00
plugins_integration build(deps): Bump anyio[curio,trio] in /testing/plugins_integration (#12033) 2024-02-26 10:51:07 -03:00
python fixtures: remove a no longer needed sort 2024-02-21 10:17:25 +02:00
acceptance_test.py main: fix reversed collection order in Session 2024-02-09 15:24:44 +02:00
conftest.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
deprecated_test.py ENH: Improve warning stacklevel (#12014) 2024-02-22 22:11:05 -08:00
test_argcomplete.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_assertion.py Enable flake8-pie 2024-02-09 11:08:33 +02:00
test_assertrewrite.py [ruff] Add 'consider-using-in' from pylint 2024-02-10 15:47:44 +01:00
test_cacheprovider.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_capture.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_collection.py main: only include package parents in collection tree for --pyargs collection arguments 2024-03-02 20:26:02 +02:00
test_compat.py [flake8-bugbear] Fixes a B017 we can actually fix and noqa the two others 2024-02-04 19:27:23 +01:00
test_config.py Consider pyproject.toml files for config if no other config files were found (#11962) 2024-02-14 16:08:45 -03:00
test_conftest.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_debugging.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_doctest.py testing/test_doctest: make `test_importmode` more realistic 2024-03-02 16:13:48 -03:00
test_entry_points.py mypy: disallow untyped defs by default (#11862) 2024-01-28 10:12:42 -03:00
test_error_diffs.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_faulthandler.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_findpaths.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_helpconfig.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_junitxml.py [ruff] Fix all consider [*cats, garfield] instead of cats + [garfield] 2024-02-02 15:18:38 +01:00
test_legacypath.py [flake8-bugbear] Fix all the useless expressions that are justified 2024-02-04 19:27:23 +01:00
test_link_resolve.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_main.py main: add `module_name` to `CollectionArgument` 2024-03-02 20:26:02 +02:00
test_mark.py [flake8-bugbear] Fix all the useless expressions that are justified 2024-02-04 19:27:23 +01:00
test_mark_expression.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_meta.py Run pre-commit on all files 2024-01-30 16:35:46 -03:00
test_monkeypatch.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_nodes.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_parseopt.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_pastebin.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_pathlib.py Change importlib to first try to import modules using the standard mechanism 2024-03-02 16:13:48 -03:00
test_pluginmanager.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_pytester.py [ruff] Add ruff's check and autofix existing issues 2024-02-02 15:18:38 +01:00
test_python_path.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_recwarn.py recwarn: fix pytest.warns handling of Warnings with multiple arguments 2024-02-16 14:14:24 +02:00
test_reports.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_runner.py runner: add support for `sys.last_exc` for post-mortem debugging on Python>=3.12 2024-02-23 15:59:32 +02:00
test_runner_xunit.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_scope.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_session.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_setuponly.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_setupplan.py #7942 test_setupplan.py migrate from testdir to Pytester (#8004) 2020-11-07 09:29:45 -03:00
test_skipping.py Enable flake8-pie 2024-02-09 11:08:33 +02:00
test_stash.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_stepwise.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_terminal.py New verbosity_test_case ini option (#11653) 2024-02-24 16:27:54 -03:00
test_threadexception.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_tmpdir.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_unittest.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_unraisableexception.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_warning_types.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
test_warnings.py Enable lint PGH004 - Use specific rule codes when using noqa 2024-02-09 11:14:36 +02:00
typing_checks.py mypy: disallow untyped defs by default (#11862) 2024-01-28 10:12:42 -03:00