Skip to content

Use importlib to avoid module name clashes for pytest - #203

Merged
nicoddemus merged 2 commits into
pytest-dev:masterfrom
neumond:master
Feb 19, 2019
Merged

nicoddemus merged 2 commits into
pytest-dev:masterfrom
neumond:master

Conversation

@neumond

@neumond neumond commented Nov 1, 2018

Copy link
Copy Markdown
Contributor

This allows simple modification for pytest --import-mode=importlib to completely avoid module naming issue if you have fresh python (>=3.5). This skips modifying sys.path, guessing package names, attempting to correctly import __init__.py and directories. This is more than enough for usual pytest workflow, e.g. if you have unimportable tests directory with files like test_something.py.

regarding loading test modules with identical names
@kxepal

kxepal commented Dec 10, 2018 •

Copy link
Copy Markdown

This is very useful! Any chances to get this merged?

@denis-trofimov

Copy link
Copy Markdown

Moscow Python Beer Meetup report rules!

@valignatev

Copy link
Copy Markdown

This would be very helpful

@sobolevn

Copy link
Copy Markdown
Member

This is an amazing feature!

@neumond

neumond commented Dec 13, 2018

Copy link
Copy Markdown
Contributor Author

screenshot from 2018-12-13 23-37-39
I've made additional checks to prove these changes actually work with pytest.
As expected, it requires only adding "importlib" to --import-mode choices.

@blueyed

blueyed commented Feb 13, 2019

Copy link
Copy Markdown
Contributor

@RonnyPfannschmidt
What is your opinion on this?

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

this is a nice solution we can use as a temporary opt in, but im under the impression we are missing a deeper detail

however i don't have time in the near future to work deeply enough into the related topic to make a good case for those details

as such i believe a good way forward is to get this in, have it as opt-in in pytest an sort out the more detailed issues after the port to pathlib is complete

@nicoddemus

Copy link
Copy Markdown
Member

We just need a CHANGELOG entry so we can merge this in. 👍

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update the CHANGELOG

@nicoddemus
nicoddemus merged commit 7c2b288 into pytest-dev:master Feb 19, 2019
@nicoddemus

Copy link
Copy Markdown
Member

Let's wait a day or two to get #207 and #215 in the next release as well. 👍

@kxepal

kxepal commented Feb 19, 2019

Copy link
Copy Markdown

🎉
Thank you all!

@nicoddemus

Copy link
Copy Markdown
Member

Thanks again @neumond for the great PR!

@blueyed

blueyed commented May 31, 2019

Copy link
Copy Markdown
Contributor

@neumond
Do you plan adding creating a PR to add this to pytest (choices/help, doc)?
(just stumbled across via py's docstring)

@blueyed

blueyed commented May 31, 2019

Copy link
Copy Markdown
Contributor

btw: would it still possible to support relative imports? (ImportError: attempted relative import with no known parent package)

@blueyed

blueyed commented Jun 1, 2019

Copy link
Copy Markdown
Contributor

Created pytest-dev/pytest#5352.

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

Successfully merging this pull request may close these issues.

8 participants