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

Use importlib to avoid module name clashes for pytest #203

Merged
merged 2 commits into from Feb 19, 2019
Merged

Use importlib to avoid module name clashes for pytest #203

merged 2 commits into from Feb 19, 2019

Conversation

neumond
Copy link
Contributor

@neumond neumond commented Nov 1, 2018

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
Copy link

kxepal commented Dec 10, 2018

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

@denis-trofimov
Copy link

Moscow Python Beer Meetup report rules!

@valignatev
Copy link

This would be very helpful

@sobolevn
Copy link
Member

This is an amazing feature!

@neumond
Copy link
Contributor Author

neumond commented Dec 13, 2018

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
Copy link
Contributor

blueyed commented Feb 13, 2019

@RonnyPfannschmidt
What is your opinion on this?

@RonnyPfannschmidt
Copy link
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
Member

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

Copy link
Member

@nicoddemus nicoddemus left a comment

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
Member

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

@kxepal
Copy link

kxepal commented Feb 19, 2019

🎉
Thank you all!

@nicoddemus
Copy link
Member

Thanks again @neumond for the great PR!

@blueyed
Copy link
Contributor

blueyed commented May 31, 2019

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

@blueyed
Copy link
Contributor

blueyed commented May 31, 2019

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

@blueyed
Copy link
Contributor

blueyed commented Jun 1, 2019

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.

None yet

8 participants