-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Feature request: Enable pytest for executable scripts without ".py" extension #3520
Comments
this should absolutely be a plugin - as far as consistent python packaging is concerned - scripts come from entrypoints of modules and there is no excuse not to have a test module |
I am constantly writing small scripts that I don't want to bother to build an entire package for. They're just scripts: I drop them in I currently work around this problem by creating a hardlink to the script (a symlink doesn't work for some reason), but that's really just silly:
This shouldn't be necessary... I understand you want to have this be a plugin but I don't really know where to start to write one for this. And I did read the documentation on how to write plugins - it's unclear to me that I could actually change the "this is not a module" behavior at all from those examples. I'm aware of the existence of pytest-console-scripts, but that's not exactly what I want here: I don't want to test the program as a script: I have real I find this problem especially confusing because the
... ie. that it should just be able to work directly on a file (not a module, mind you, a file). Is there some magic trick I'm missing here or I'm the only idiot out there writing tests for his small silly non-packaged programs? :) |
It's in most cases good to write tests, it's just not a core pytest concern to collect small executables Personally I just create packages for utility scripts and call it a day |
As for writing a plugin, the collect_file hook should be a good starting point, unfortunately you will need to create a new kind of Module collector to sort out the finer details Sorry for the terse answer, I'm on mobile on a train ride |
btw: at least the error message could be improved maybe:
IIRC a possible workaround is to use |
|
Oh yeah, remembered it wrong: #4476 |
okay, so i should follow #4476 is what you're saying? :) |
First of all, let me say that I love pytest! Thanks for your great work.
As far as I understand it is considered standard practice to name executable python scripts without the ".py" extension (e.g.,
pip
,pytest
, etc.) - at least on linux. Normally such scripts do not contain much code, but it might still be useful to be able to test them with pytest, which is currently not possible.Test case:
Actual result:
Expected:
The expected behavior could be implemented using a plugin, but I personally think it should be solved by pytest itself...
The text was updated successfully, but these errors were encountered: