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

Module re-write doesn't work with non dist-info based installations #6301

nehaljwani opened this issue Dec 1, 2019 · 3 comments · Fixed by #6313

Module re-write doesn't work with non dist-info based installations #6301

nehaljwani opened this issue Dec 1, 2019 · 3 comments · Fixed by #6313


Copy link

@nehaljwani nehaljwani commented Dec 1, 2019

More context behind this issue is available at: pytest-dev/pytest-mock#167


The function _iter_rewritable_modules doesn't detect modules that can be rewritten, if they are installed by a method which doesn't adopt the dist-info format.

An easy way to reproduce the problem is to: pip install pytest-mock in one environment and pip install -e 'git+' in another and compare the output for:

import importlib_metadata
from _pytest.config import _iter_rewritable_modules

for x in importlib_metadata.distributions():
  if x.metadata['Name']=='pytest-mock':
    for _file in x.files:
      print("file: {}; module_or_pkg_name: {}".format(str(_file), list(_iter_rewritable_modules([str(_file)]))))

Because of this problem, rpm maintainers are unable to run the tests for pytest-mock, since they rely on python install which creates egg-info directories.


This comment has been minimized.

Copy link

@nicoddemus nicoddemus commented Dec 3, 2019

Copying the output from pytest-dev/pytest-mock#167 (comment):

Output from dist-info:

file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/INSTALLER; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/LICENSE; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/METADATA; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/RECORD; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/WHEEL; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/entry_points.txt; module_or_pkg_name: []
file: pytest_mock-1.11.3.dev2+g1c5e8e9.d20191031.dist-info/top_level.txt; module_or_pkg_name: []
file: pytest_mock/; module_or_pkg_name: ['pytest_mock'] <---------- Good!
file: pytest_mock/__pycache__/__init__.cpython-36.pyc; module_or_pkg_name: []
file: pytest_mock/__pycache__/_version.cpython-36.pyc; module_or_pkg_name: []
file: pytest_mock/__pycache__/plugin.cpython-36.pyc; module_or_pkg_name: []
file: pytest_mock/; module_or_pkg_name: []
file: pytest_mock/; module_or_pkg_name: []

From egg:

file: .gitignore; module_or_pkg_name: []
file: .pre-commit-config.yaml; module_or_pkg_name: []
file: CHANGELOG.rst; module_or_pkg_name: []
file: HOWTORELEASE.rst; module_or_pkg_name: []
file: LICENSE; module_or_pkg_name: []
file: README.rst; module_or_pkg_name: []
file: setup.cfg; module_or_pkg_name: []
file:; module_or_pkg_name: ['setup'] <-------- ?????????????
file: tox.ini; module_or_pkg_name: []
file: .github/FUNDING.yml; module_or_pkg_name: []
file: .github/workflows/main.yml; module_or_pkg_name: []
file: src/pytest_mock/; module_or_pkg_name: [] <-------- Hey, why u ditch me?
file: src/pytest_mock/; module_or_pkg_name: []
file: src/pytest_mock/; module_or_pkg_name: []
file: src/pytest_mock.egg-info/PKG-INFO; module_or_pkg_name: []
file: src/pytest_mock.egg-info/SOURCES.txt; module_or_pkg_name: []
file: src/pytest_mock.egg-info/dependency_links.txt; module_or_pkg_name: []
file: src/pytest_mock.egg-info/entry_points.txt; module_or_pkg_name: []
file: src/pytest_mock.egg-info/requires.txt; module_or_pkg_name: []
file: src/pytest_mock.egg-info/top_level.txt; module_or_pkg_name: []
file: tests/; module_or_pkg_name: []
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 3, 2019
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 4, 2019

This comment has been minimized.

Copy link

@felixonmars felixonmars commented Dec 23, 2019

The problem is present on the 4.6 maintenance branch too. I have backported the fix to 4.6.8 to fix pytest-mock's tests under Python 2.7 in Arch. Is it possible to cherry-pick the patch into 4.6 maintenance branch?

felixonmars-bot pushed a commit to felixonmars/archlinux-community that referenced this issue Dec 23, 2019
backport fix for pytest-dev/pytest#6301

git-svn-id: file:///srv/repos/svn-community/svn@539143 9fca08f4-af9d-4005-b8df-a31f2cc04f65

This comment has been minimized.

Copy link

@asottile asottile commented Dec 23, 2019

yep! would you like to open a PR? you can target the 4.6-maintenance branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
5 participants
You can’t perform that action at this time.