jendrikseipp / vulture

Find dead Python code
MIT License
3.48k stars 152 forks source link

How to ignore all test_*.py files? #260

Closed srossross closed 1 year ago

srossross commented 3 years ago

The exclude argument does not appear to work the way I was expecting

vulture plantiga_analytics/ --exclude 'test_*.py'

plantiga_analytics/test_compute_main.py:290: unused attribute 'return_value' (60% confidence)
plantiga_analytics/test_compute_main.py:292: unused attribute 'side_effect' (60% confidence)
plantiga_analytics/test_compute_main.py:294: unused attribute 'return_value' (60% confidence)
noorul commented 3 years ago

Maybe you need '*test_*.py

RJ722 commented 3 years ago

@noorul is correct. You can also use something like **/*/test_*.py.

Cheaterman commented 1 year ago

Thanks, this was helpful :-) but I personally don't quite understand why in my situation I need vulture '--exclude=*env/**' . for my venv situated at ./env - I tried --exclude=env/**, ./env/**, /env/**, nothing seems to work :-)

jendrikseipp commented 1 year ago

Thanks for the report! The --exclude patterns are matched against absolute paths. I clarified this in the help output and the README now.

sliedes commented 1 year ago

Thanks for the report! The --exclude patterns are matched against absolute paths. I clarified this in the help output and the README now.

I'm curious about the rationale for this design decision. It seems rather counterintuitive and error-prone to me; it may lead to things like people with different usernames (and thus different home directories) getting different warnings unless the globs are carefully crafted.

jendrikseipp commented 1 year ago

@sliedes Can you provide a concrete problematic example for this, please? Which behaviour would you expect for --exclude?

sliedes commented 1 year ago

It just feels very surprising to me; normally, in my experience projects are developed so that you have some "project directory", perhaps a checked out repository, and you'd in my view want the checks to run deterministically inside it regardless of its location in the filesystem.

I have not encountered any pathological examples in practice (well, I only started looking into vulture last week), but I could imagine patterns written with less care like (borrowing from the discussion above) --exclude **/env/*, where everything gets excluded for the poor new intern whose username happens to be "env" and home directory /home/env.

It just seems like a needless pitfall to me. :)

jendrikseipp commented 1 year ago

Thanks for the explanation! I hope that #310 will improve the situation.