|
| 1 | +import platform |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +from inspect import cleandoc |
| 5 | + |
| 6 | +import jaraco.path |
| 7 | +import pytest |
| 8 | + |
| 9 | +pytestmark = pytest.mark.integration |
| 10 | + |
| 11 | +VIRTUALENV = (sys.executable, "-m", "virtualenv") |
| 12 | + |
| 13 | + |
| 14 | +def run(cmd, **kwargs): |
| 15 | + proc = subprocess.run(cmd, encoding="utf-8", capture_output=True, **kwargs) |
| 16 | + if proc.returncode != 0: |
| 17 | + pytest.fail(f"Command {cmd} failed with:\n{proc.stdout=!s}\n{proc.stderr=!s}") |
| 18 | + return proc.stdout |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.skipif( |
| 22 | + platform.system() != "Linux", |
| 23 | + reason="only demonstrated to fail on Linux in #4399", |
| 24 | +) |
| 25 | +def test_interop_pkg_resources_iter_entry_points(tmp_path, venv): |
| 26 | + """ |
| 27 | + Importing pkg_resources.iter_entry_points on console_scripts |
| 28 | + seems to cause trouble with zope-interface, when deprecates installation method |
| 29 | + is used. See #4399. |
| 30 | + """ |
| 31 | + project = { |
| 32 | + "pkg": { |
| 33 | + "foo.py": cleandoc( |
| 34 | + """ |
| 35 | + from pkg_resources import iter_entry_points |
| 36 | +
|
| 37 | + def bar(): |
| 38 | + print("Print me if you can") |
| 39 | + """ |
| 40 | + ), |
| 41 | + "setup.py": cleandoc( |
| 42 | + """ |
| 43 | + from setuptools import setup, find_packages |
| 44 | +
|
| 45 | + setup( |
| 46 | + install_requires=["zope-interface==6.4.post2"], |
| 47 | + entry_points={ |
| 48 | + "console_scripts": [ |
| 49 | + "foo=foo:bar", |
| 50 | + ], |
| 51 | + }, |
| 52 | + ) |
| 53 | + """ |
| 54 | + ), |
| 55 | + } |
| 56 | + } |
| 57 | + jaraco.path.build(project, prefix=tmp_path) |
| 58 | + cmd = [venv.exe("pip"), "install", "-e", ".", "--no-use-pep517"] |
| 59 | + run(cmd, cwd=tmp_path / "pkg") |
| 60 | + out = run([venv.exe("foo")]) |
| 61 | + assert "Print me if you can" in out |
0 commit comments