Skip to content
Myr

fix uninstalled package tests under tox

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 88bcf78 · Browse files · 3 files+15 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−7 removed

  • tests:+0 added−3 removed
  • other:+15 added−4 removed

3 files+15 added−7 removed

modified:src/flask/scaffold.py+14 added-4 removed
1import importlib.util2import os3import pathlib4import pkgutil5import sys6import typing as t7from collections import defaultdict
772 unmodified lines
780 f" import hooks."781 )782783784def _path_is_relative_to(path: pathlib.PurePath, base: str) -> bool:785 # Path.is_relative_to doesn't exist until Python 3.9786 try:787 path.relative_to(base)788 return True789 except ValueError:790 return False791792793def _find_package_path(import_name):794 """Find the path that contains the package or module."""795 root_mod_name, _, _ = import_name.partition(".")796
14 unmodified lines
811 if root_spec.origin in {"namespace", None}:812 package_spec = importlib.util.find_spec(import_name)813 if package_spec is not None and package_spec.submodule_search_locations:814 # Pick the path in the namespace that contains the submodule.805 package_path = os.path.commonpath(806 package_spec.submodule_search_locations815 package_path = pathlib.Path(816 os.path.commonpath(package_spec.submodule_search_locations)817 )818 search_locations = (819 location820 for location in root_spec.submodule_search_locations811 if package_path.startswith(location)821 if _path_is_relative_to(package_path, location)822 )823 else:824 # Pick the first path.825 search_locations = iter(root_spec.submodule_search_locations)
48 unmodified lines
874 package_path = _find_package_path(import_name)875 py_prefix = os.path.abspath(sys.prefix)876877 # installed to the system868 if package_path.startswith(py_prefix):878 if _path_is_relative_to(pathlib.PurePath(package_path), py_prefix):879 return py_prefix, package_path880881 site_parent, site_folder = os.path.split(package_path)882
17 unmodified lines
modified:tests/test_instance_config.py-3 removed
13 unmodified lines
14 app = flask.Flask(__name__, instance_path=str(modules_tmpdir))15 assert app.instance_path == str(modules_tmpdir)161718@pytest.mark.xfail(reason="weird interaction with tox")18def test_main_module_paths(modules_tmpdir, purge_module):19 app = modules_tmpdir.join("main_app.py")20 app.write('import flask\n\napp = flask.Flask("__main__")')21 purge_module("main_app")
3 unmodified lines
25 here = os.path.abspath(os.getcwd())26 assert app.instance_path == os.path.join(here, "instance")272830@pytest.mark.xfail(reason="weird interaction with tox")29def test_uninstalled_module_paths(modules_tmpdir, purge_module):30 app = modules_tmpdir.join("config_module_app.py").write(31 "import os\n"32 "import flask\n"
6 unmodified lines
3940 assert app.instance_path == str(modules_tmpdir.join("instance"))414245@pytest.mark.xfail(reason="weird interaction with tox")43def test_uninstalled_package_paths(modules_tmpdir, purge_module):44 app = modules_tmpdir.mkdir("config_package_app")45 init = app.join("__init__.py")46 init.write(
91 unmodified lines
modified:tox.ini+1 added
7 unmodified lines
8 docs9skip_missing_interpreters = true1011[testenv]12envtmpdir = {toxworkdir}/tmp/{envname}13deps =14 -r requirements/tests.txt15 min: -r requirements/tests-pallets-min.txt16 dev: -r requirements/tests-pallets-dev.txt
18 unmodified lines