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

Make --ignore flag work with --pyargs #3287

Open
rth opened this issue Mar 6, 2018 · 5 comments
Open

Make --ignore flag work with --pyargs #3287

rth opened this issue Mar 6, 2018 · 5 comments
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch

Comments

@rth
Copy link

rth commented Mar 6, 2018

I just discovered the --pyargs option and it's very practical. However it does not seem to take into account the --ignore options.

Example,

$ pytest --doctest-modules  --pyargs setuptools
============================================ test session starts ============================================
platform linux -- Python 3.6.4, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /home/rth, inifile:
plugins: profiling-1.2.11
collected 6 items                                                                                           

anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/namespaces.py .                       [ 16%]
anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/package_index.py .                    [ 33%]
anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/sandbox.py .                          [ 50%]
anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/command/develop.py .                  [ 66%]
anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/command/install_lib.py .              [ 83%]
anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/command/py36compat.py .               [100%]

========================================= 6 passed in 0.52 seconds ==========================================

running,

pytest --doctest-modules --ignore develop.py  --pyargs setuptools

produces exactly identical output, while I would have expected the develop.py not to be tested.
Here is another example of this same issue.

Is there a way around it?

@nicoddemus
Copy link
Member

Hi @rth,

--ignore only checks for paths and does not currently work with --pyargs, but I guess it could be made to work with it.

@nicoddemus nicoddemus added type: enhancement new feature or API change, should be merged into features branch topic: collection related to the collection phase labels Mar 6, 2018
@nicoddemus nicoddemus changed the title Ignored --ignore flag when using --pyargs pkg Make --ignore flag work with --pyargs Mar 6, 2018
@rth
Copy link
Author

rth commented Mar 7, 2018

Thanks for the confirmation, @nicoddemus !

Providing the full path to --ignore, in my case

anaconda2/envs/testn-env/lib/python3.6/site-packages/setuptools/command/develop.py

does work even for --pyargs.

I'm wondering if this couldn't be solved by just adding support for regexp in --ignore. This is also something that might be nice to have independently of this issue, I think.

As far as I can tell all --pyargs does is to finding the full path path to the package here.
And roughly speaking, if one were to replace,

if py.path.local(path) in ignore_paths:

by

if re.match(py.path.local(path), ' '.join(ignore_paths))

(or something based on fnmatch) it could work, I imagine.

Would this feature be acceptable for pytest? Am I missing something? To avoid breaking backward compatibility fnmatch might be better, but even then I'm not sure this wouldn't break existing setups...

@rth
Copy link
Author

rth commented Mar 7, 2018

To avoid breaking backward compatibility fnmatch might be better, but even then I'm not sure this wouldn't break existing setups...

Or maybe add another CLI option similar to --ignore but for regexp, e.g. --ignore-regexp ...

@nicoddemus
Copy link
Member

Would this feature be acceptable for pytest? Am I missing something? To avoid breaking backward compatibility fnmatch might be better, but even then I'm not sure this wouldn't break existing setups...

Seems reasonable, and if we use re.search instead of re.match we probably won't even break backward compatibility.

@ngie-eign
Copy link

I was wondering why this functionality didn't work as expected. I am using 4.6.x (2.7) and 6.2.x (3.x).
I'm curious... rhetorically speaking, why aren't paths being ignored after the package(s) have been imported? Seems backwards to apply it beforehand and only in select cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants