Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.10.0: pytest is failing #86

Closed
kloczek opened this issue Nov 19, 2022 · 7 comments
Closed

3.10.0: pytest is failing #86

kloczek opened this issue Nov 19, 2022 · 7 comments

Comments

@kloczek
Copy link

kloczek commented Nov 19, 2022

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix>
  • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -p no:checkdocs
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/zipp-3.10.0, configfile: pytest.ini
plugins: freezegun-0.4.2
collected 36 items / 1 error

================================================================================== ERRORS ==================================================================================
___________________________________________________________________ ERROR collecting zipp/py310compat.py ___________________________________________________________________
/usr/lib/python3.8/site-packages/_pytest/runner.py:339: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.8/site-packages/_pytest/runner.py:370: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/lib/python3.8/site-packages/_pytest/doctest.py:548: in collect
    module = import_path(
/usr/lib/python3.8/site-packages/_pytest/pathlib.py:556: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('zipp.py310compat', '/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/zipp/py310compat.py', PosixPath('/home/tkloczko/rpmbuild/BUILD/zipp-3.10.0/zipp/py310compat.py'))
============================================================================= warnings summary =============================================================================
../../../../../usr/lib/python3.8/site-packages/pytest_freezegun.py:17: 72 warnings
  /usr/lib/python3.8/site-packages/pytest_freezegun.py:17: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    if LooseVersion(pytest.__version__) < LooseVersion('3.6.0'):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= short test summary info ==========================================================================
ERROR zipp/py310compat.py - _pytest.pathlib.ImportPathMismatchError: ('zipp.py310compat', '/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/zipp/...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================== 72 warnings, 1 error in 0.26s =======================================================================

ABove is with pytest-freezegun 0.4.2.

@kloczek
Copy link
Author

kloczek commented Nov 19, 2022

Looking on file name I suppose that this file sontains units which are for python +3.10.
If that is true on 3.8.x tose units shoud be skipped.

@jaraco
Copy link
Owner

jaraco commented Nov 23, 2022

This issue is the same one we've seen many times before on jaraco/skeleton projects. The problem is that zipp is installed to two different locations, in site-packages and in the build directory. I typically avoid these errors by using editable installs so there's one copy of the code installed.

You'll want to make sure that python -c 'import zipp; print(zipp.__file__)' returns the path to the package you're attempting to test.

I'm sorry Python packaging is so tricky. I wish there were a better way.

@kloczek
Copy link
Author

kloczek commented Nov 23, 2022

As zipp is using setuptools-scm as pep517 backend build generated .egg-info directory so in source tree is in editable mode. Howvere after install .whl archive in </install/prefix> in that directory there are as well .dist-info metadata.
Neverteheless in in this case pytest fails on collecting details about test units.

@kloczek
Copy link
Author

kloczek commented Nov 23, 2022

Because $PYTHONPATH is used it shoud be used what is provided in </install/prefix>.

@kloczek
Copy link
Author

kloczek commented Nov 23, 2022

Just foud workaround by use --import-mode=importlib so definitelly something is wrong with some imports.

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-zipp-3.10.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --import-mode=importlib -p no:checkdocs
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.15, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/zipp-3.10.0, configfile: pytest.ini
plugins: mock-3.10.0
collected 36 items

tests/test_zipp.py .................................                                                                                                                 [ 91%]
zipp/__init__.py ...                                                                                                                                                 [100%]

============================================================================ 36 passed in 0.89s ============================================================================

@jaraco
Copy link
Owner

jaraco commented Dec 25, 2022

I'm glad you found a workaround. I have considered adopting import-mode=importlib for all of my projects, but that mode has documented limitations and other degradations that make it difficult to adopt universally. I'm working with the pytest project for it to provide some technique that works for all projects, but as it currently stands, there's no good solution.

Since the test suite is working in CI and because you've found a workaround for your installation of it, and because there's no other concrete suggestion on what this project should do differently, I'm declaring that good enough.

@jaraco jaraco closed this as completed Dec 25, 2022
@kloczek
Copy link
Author

kloczek commented Dec 25, 2022

Thank you to let me know 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants