From ebfe16c3097d227d7f3ac5e960d853513d2f71b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 24 May 2022 19:26:39 +0200 Subject: [PATCH 1/4] Make test_setup_install_includes_dependencies easier to debug --- setuptools/tests/test_easy_install.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 726f9fda5a..4d454ee0e5 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -475,21 +475,26 @@ def test_setup_install_includes_dependencies(self, tmp_path, mock_index): '--install-platlib', str(install_root), ] env = {"PYTHONPATH": str(install_root), "__EASYINSTALL_INDEX": mock_index.url} - with pytest.raises(subprocess.CalledProcessError) as exc_info: - subprocess.check_output( - cmd, cwd=str(project_root), env=env, stderr=subprocess.STDOUT, text=True - ) + cp = subprocess.run( + cmd, + cwd=str(project_root), + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + ) + assert cp.returncode != 0 try: assert '/does-not-exist/' in {r.path for r in mock_index.requests} assert next( line - for line in exc_info.value.output.splitlines() + for line in cp.stdout.splitlines() if "not find suitable distribution for" in line and "does-not-exist" in line ) except Exception: - if "failed to get random numbers" in exc_info.value.output: - pytest.xfail(f"{sys.platform} failure - {exc_info.value.output}") + if "failed to get random numbers" in cp.stdout: + pytest.xfail(f"{sys.platform} failure - {cp.stdout}") raise def create_project(self, root): From d22e554c716e4ff89c905022531d2af6b1ae944f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 24 May 2022 19:26:56 +0200 Subject: [PATCH 2/4] Preserve PYTHONPATH in test_setup_install_includes_dependencies So if the tested setuptools is only located in manually set $PYTHONPATH, it still tests that setuptools instead of the previously installed one in site-packages. --- setuptools/tests/test_easy_install.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 4d454ee0e5..84cdb21a69 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -474,7 +474,11 @@ def test_setup_install_includes_dependencies(self, tmp_path, mock_index): '--install-purelib', str(install_root), '--install-platlib', str(install_root), ] - env = {"PYTHONPATH": str(install_root), "__EASYINSTALL_INDEX": mock_index.url} + env = {**os.environ, "__EASYINSTALL_INDEX": mock_index.url} + if "PYTHONPATH" in env: + env["PYTHONPATH"] = str(install_root) + os.pathsep + env["PYTHONPATH"] + else: + env["PYTHONPATH"] = str(install_root) cp = subprocess.run( cmd, cwd=str(project_root), From b08401ddb051631ca41a349fbb566f1715cb9cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 24 May 2022 19:28:39 +0200 Subject: [PATCH 3/4] No need to set PYTHONPATH in test_setup_install_includes_dependencies at all --- setuptools/tests/test_easy_install.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 84cdb21a69..73a8dfff08 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -475,10 +475,6 @@ def test_setup_install_includes_dependencies(self, tmp_path, mock_index): '--install-platlib', str(install_root), ] env = {**os.environ, "__EASYINSTALL_INDEX": mock_index.url} - if "PYTHONPATH" in env: - env["PYTHONPATH"] = str(install_root) + os.pathsep + env["PYTHONPATH"] - else: - env["PYTHONPATH"] = str(install_root) cp = subprocess.run( cmd, cwd=str(project_root), From fd4a4822bb4025801d6c4b8bf000a17f0cd4b337 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 7 Jun 2022 14:37:38 +0100 Subject: [PATCH 4/4] Add news fragment --- changelog.d/3336.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3336.misc.rst diff --git a/changelog.d/3336.misc.rst b/changelog.d/3336.misc.rst new file mode 100644 index 0000000000..288b1eb3ac --- /dev/null +++ b/changelog.d/3336.misc.rst @@ -0,0 +1 @@ +Modified ``test_setup_install_includes_dependencies`` to work with custom ``PYTHONPATH`` –- by :user:`hroncok` \ No newline at end of file