Closed isotherm closed 5 years ago
The purpose of pytest-console-scripts is to run console scripts that the module under test installs. Usually they would not be installed into /usr/bin
and other global directories like that. However I imagine you might want to run some python scripts that your interpreter already has (and that are not part of the module under test) as part of the test and you might want to run them inside of the test process (for speed or code coverage or something like this). I don't see a good reason why this should not work in principle and also the existing method of script discovery is quite hacky and should probably be refactored to something similar to your proposal.
This alone would not solve #17 because there the idea is to use a relative path to some python script that might not even be in the PATH
. However, it should be possible to update the API in a way that would make both your use case and #17 work. For example we could treat the command
argument given to script_runner.run
as something to search in PATH
unless it looks like an path, in which case we use it directly.
Yes, pip install is placing my module's console_scripts into /usr/local/bin whereas the python binary is in /usr/bin. So I think that my usage matches the purpose of pytest-console-scripts, but currently it cannot cleanly run them in-process. (I think I could specify each command as local/script_name
, but I don't consider this clean since it's platform-specific.)
distutils.spawn.find_executable
seems to work also with relative paths, but it appears to be relative to the working directory rather than the path of a particular script.
I just stumbled across the same issue on Ubuntu 18.04. Here, when installing a package system wide, console scripts are also installed to /usr/local/bin
while the interpreter resides in /usr/bin
.
I am not sure what the cleanest solution is and if distutils.spawn.find_executable
works in all cases but having the possibility to tweak the command lookup in inprocess
mode is definitely needed. Even simply being able to specify the full path to the command would already be a huge help and enable me to implement the discovery as part of the test code.
distutils.spawn.find_executable
is present in Python >=2.6 and >=3.0. I will create a pull request.
On my current system (CentOS), console scripts are not installed in the same folder as Python. (They are installed in /usr/local/bin rather than /usr/bin.)
To fix this, I am wondering if a fix like below at line 108 could work, or if there is a design consideration I am missing:
script = py.path.local(distutils.spawn.find_executable(command))
It looks like this would also resolve Issue #17.