Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
runs-on: ${{ matrix.platform }}
env:
SETUPTOOLS_USE_DISTUTILS: ${{ matrix.distutils }}
PY_IGNORE_IMPORTMISMATCH: ${{ contains(matrix.python, 'pypy') && 1 }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kloczek, there is a problem with pytest that might be causing the problems you are seeing:
pytest-dev/pytest#2042

This seems to be related to the contents of your log.
I think you can try PY_IGNORE_IMPORTMISMATCH=1 as an env var to see how it goes.

Copy link

@kloczek kloczek Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can try PY_IGNORE_IMPORTMISMATCH=1 as an env var to see how it goes.

Tested. Result with pytest 6.2.5 is exactly the same.

+ cd setuptools-60.5.4
+ export PY_IGNORE_IMPORTMISMATCH=1
+ PY_IGNORE_IMPORTMISMATCH=1
+ PYTHONDONTWRITEBYTECODE=1
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-setuptools-60.5.4-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ pytest -ra -p no:randomly setuptools -W ignore::DeprecationWarning --import-mode=importlib
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/setuptools-60.5.4, configfile: pytest.ini
plugins: shutil-1.7.0, forked-1.4.0, cov-3.0.0, virtualenv-1.7.0, checkdocs-2.7.1, flake8-1.0.7, xdist-2.5.0
collected 155 items / 20 errors / 1 skipped / 134 selected

================================================================================== ERRORS ==================================================================================
___________________________________________________________ ERROR collecting setuptools/tests/test_bdist_egg.py ____________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/setuptools-60.5.4/setuptools/tests/test_bdist_egg.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
setuptools/tests/test_bdist_egg.py:11: in <module>
    from . import contexts
E   ImportError: attempted relative import with no known parent package
___________________________________________________________ ERROR collecting setuptools/tests/test_build_ext.py ____________________________________________________________

[..]

========================================================================= short test summary info ==========================================================================
SKIPPED [1] setuptools/tests/test_msvc.py:17: could not import 'distutils.msvc9compiler': No module named 'winreg'
ERROR setuptools/tests/test_bdist_egg.py
ERROR setuptools/tests/test_build_ext.py
ERROR setuptools/tests/test_build_meta.py
ERROR setuptools/tests/test_config.py
ERROR setuptools/tests/test_depends.py
ERROR setuptools/tests/test_develop.py
ERROR setuptools/tests/test_dist.py
ERROR setuptools/tests/test_dist_info.py
ERROR setuptools/tests/test_easy_install.py
ERROR setuptools/tests/test_egg_info.py
ERROR setuptools/tests/test_install_scripts.py
ERROR setuptools/tests/test_msvc.py
ERROR setuptools/tests/test_namespaces.py
ERROR setuptools/tests/test_packageindex.py
ERROR setuptools/tests/test_sdist.py
ERROR setuptools/tests/test_test.py
ERROR setuptools/tests/test_upload_docs.py
ERROR setuptools/tests/test_virtualenv.py
ERROR setuptools/tests/test_wheel.py
ERROR setuptools/tests/integration/test_pip_install_sdist.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 20 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================== 1 skipped, 20 errors in 2.82s =======================================================================

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logs seem very different for me 😄, looks like you are making progress!

Can you confirm that you are using the exact same flags used in setuptools own tox.ini file and /or .github/workflows/main.yml?

Can you also confirm that you are running pytest from a directory with all the configuration files present in the repository (pyproject.toml, pytest.ini, setup.cfg, conftest.py)?

TOXENV: native
steps:
- uses: actions/checkout@v2
- name: Setup Python
Expand All @@ -31,6 +33,14 @@ jobs:
- name: Install tox
run: |
python -m pip install tox
- name: Skip some Pytest plugins on PyPy
if: contains(matrix.python, 'pypy') && matrix.distutils == 'local' && matrix.platform != 'windows-latest'
# PyPy 3.7 imports `distutils` in its `sysconfig`, which would trigger
# `_distutils_hack` and potentially mess imports for `pep517` (used by some plugins)
# https://foss.heptapod.net/pypy/pypy/-/blob/8301595a71447bbe58bb61c5ecd83d93cfda5eb0/lib-python/3/sysconfig.py#L461-473
# https://foss.heptapod.net/pypy/pypy/-/blob/8301595a71447bbe58bb61c5ecd83d93cfda5eb0/lib_pypy/_sysconfigdata.py#L5
# https://github.com/pypa/pep517/blob/a942316305395f8f757f210e2b16f738af73f8b8/pep517/in_process/_in_process.py#L76-L86
run: echo 'PYTEST_ADDOPTS=-p no:perf -p no:checkdocs' >> $GITHUB_ENV
- name: Run tests
run: tox -- --cov-report xml
- name: Publish coverage
Expand All @@ -51,6 +61,7 @@ jobs:
runs-on: windows-latest
env:
SETUPTOOLS_USE_DISTUTILS: ${{ matrix.distutils }}
TOXENV: native
steps:
- uses: actions/checkout@v2
- name: Install Cygwin with Python and tox
Expand Down
21 changes: 20 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import os
import sys
from importlib.util import spec_from_file_location

import pytest


pytest_plugins = 'setuptools.tests.fixtures'
class _ImportFinder:
"""Allow in-tree pytest plugins when setuptools is installed from distribution"""

_root_dir = os.path.dirname(__file__)
_handled = ('setuptools.tests', 'pkg_resources.tests')

@classmethod
def find_spec(cls, fullname, _path, _target=None):
if all(not fullname.startswith(n) for n in cls._handled):
return None

loc = os.path.join(cls._root_dir, *fullname.split("."))
loc = os.path.join(loc, "__init__.py") if os.path.isdir(loc) else f"{loc}.py"
return spec_from_file_location(fullname, loc)


sys.meta_path.append(_ImportFinder)
pytest_plugins = ['setuptools.tests.fixtures']


def pytest_addoption(parser):
Expand Down
4 changes: 3 additions & 1 deletion pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ def test_setuptools_not_imported(self):
that action doesn't cause setuptools to be imported.
"""
lines = (
'import pkg_resources',
'import sys',
'sys.modules.pop("setuptools", None)',
# ^-- make sure test does not fail if imported elsewhere
'import pkg_resources',
(
'assert "setuptools" not in sys.modules, '
'"setuptools was imported"'
Expand Down
10 changes: 7 additions & 3 deletions setuptools/tests/test_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

from setuptools import depends

from . import __name__ as __pkg__


class TestGetModuleConstant:

def test_basic(self):
def test_basic(self, monkeypatch):
"""
Invoke get_module_constant on a module in
the test package.
"""
mod_name = 'setuptools.tests.mod_with_constant'
mod_name = f'{__pkg__}.mod_with_constant'
monkeypatch.delitem(sys.modules, mod_name, None)
# ^-- make sure test does not fail if imported elsewhere
val = depends.get_module_constant(mod_name, 'value')
assert val == 'three, sir!'
assert 'setuptools.tests.mod_with_constant' not in sys.modules
assert mod_name not in sys.modules
2 changes: 1 addition & 1 deletion setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch):
with contexts.environment(PYTHONPATH=temp_install_dir):
cmd = [
sys.executable,
'-m', 'setup',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems to rely on the fact that it runs from the project root (that contains a setup.py) file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. That test was really janky, relying on Setuptools' own setup.py (with all its distribution setup) just to ignore it and invoke easy_install. Yes, I believe this change is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover: runpy also injects the CWD into PYTHONPATH (which will effectively be prepended to temp_install_dir that the CM above puts there).

Copy link
Contributor Author

@abravalheri abravalheri Jan 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid the only way of preventing this from happening would be either adopting a src-layout or using the changedir trick proposed in the original issue.

The problem with the changedir being that it breaks pytest-enabler and (a single) doctest...


P.S.: The solution proposed by @webknjaz of separating the CI in 2 stages (build, test) and rm-ing the files that are not part of the tests would also work, I think...

'-c', '__import__("setuptools").setup()',
'easy_install',
'--index-url', mock_index.url,
'--exclude-scripts',
Expand Down
27 changes: 7 additions & 20 deletions setuptools/tests/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,18 @@ def test_namespace_package_installed_and_cwd(self, tmpdir):
with test.test.paths_on_pythonpath([str(target)]):
subprocess.check_call(pkg_resources_imp, cwd=str(pkg_A))

def test_packages_in_the_same_namespace_installed_and_cwd(self, tmpdir):
def test_packages_in_the_same_namespace_installed_and_cwd(self, tmpdir, venv):
"""
Installing one namespace package and also have another in the same
namespace in the current working directory, both of them must be
importable.
"""
pkg_A = namespaces.build_namespace_package(tmpdir, 'myns.pkgA')
pkg_B = namespaces.build_namespace_package(tmpdir, 'myns.pkgB')
target = tmpdir / 'packages'
# use pip to install to the target directory
install_cmd = [
sys.executable,
'-m',
'pip.__main__',
'install',
str(pkg_A),
'-t', str(target),
]
subprocess.check_call(install_cmd)
namespaces.make_site_dir(target)

# ensure that all packages import and pkg_resources imports
pkg_resources_imp = [
sys.executable,
'-c', 'import pkg_resources; import myns.pkgA; import myns.pkgB',
]
with test.test.paths_on_pythonpath([str(target)]):
subprocess.check_call(pkg_resources_imp, cwd=str(pkg_B))
# Install pkgA regularly
venv.run(['python', '-m', 'pip', 'install', str(pkg_A)])

# ensure that all packages import when running from pkgB dir
cmd = ['python', '-c', 'import pkg_resources, myns.pkgA, myns.pkgB']
venv.run(cmd, cwd=str(pkg_B))
6 changes: 5 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ deps =
# Ideally all the dependencies should be set as "extras"
commands =
pytest {posargs}
usedevelop = True
usedevelop =
native: False
!native: True
extras = testing
passenv =
SETUPTOOLS_USE_DISTUTILS
PY_IGNORE_IMPORTMISMATCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I haven't heard of this thing. Is it documented anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 digging issues: pytest-dev/pytest#2042

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, looks like my google-fu let me down, thanks for this link!

PYTEST_ADDOPTS
windir # required for test_pkg_resources
# honor git config in pytest-perf
HOME
Expand Down