Skip to content

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

@nehaljwani

Description

@nehaljwani

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

TL;DR:

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+https://github.com/pytest-dev/pytest-mock#egg=pytest-mock' 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 setup.py install which creates egg-info directories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions