New issue 257: Shell commands fail on WIndows due to popen shell=False in
Action._popen
https://bitbucket.org/hpk42/tox/issue/257/shell-commands-fail-on-windows-due-to
stefano-m:
Hello,
I am using tox 2.0.2 and Python 2.7 on Windows 7.
As part of my tox tests, I need to run gulp and other npm-related commands.
To do so, I first run npm install and then e.g. run gulp that has been
installed in the node_modules directory.
The relevant part of my tox.ini looks like
[testenv]
whitelist_externals = npm
commands =
npm install
{toxinidir}/node_modules/.bin/gulp
When I run tox, I get the following error when gulp is run:
py27-win32 runtests: commands[0] | npm install
py27-win32 runtests: commands[1] |
F:\my_project\my_project/node_modules/.bin/gulp
ERROR: invocation failed (errno 8), args:
['F:\\my_project\\my_project/node_modules/.bin/gulp'], cwd:
F:\my_project\my_project
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\tox.exe\__main__.py", line 9, in <module>
File "C:\Python27\lib\site-packages\tox\session.py", line 39, in main
retcode = Session(config).runcommand()
File "C:\Python27\lib\site-packages\tox\session.py", line 367, in runcommand
return self.subcommand_test()
File "C:\Python27\lib\site-packages\tox\session.py", line 540, in
subcommand_test
self.runtestenv(venv)
File "C:\Python27\lib\site-packages\tox\session.py", line 548, in runtestenv
venv.test(redirect=redirect)
File "C:\Python27\lib\site-packages\tox\venv.py", line 360, in test
ignore_ret=ignore_ret)
File "C:\Python27\lib\site-packages\tox\venv.py", line 384, in _pcall
return action.popen(args, cwd=cwd, env=env, redirect=redirect,
ignore_ret=ignore_ret)
File "C:\Python27\lib\site-packages\tox\session.py", line 130, in popen
stdout=stdout, stderr=STDOUT)
File "C:\Python27\lib\site-packages\tox\session.py", line 218, in _popen
stdout=stdout, stderr=stderr, env=env)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
The same configuration works OK on Linux.
I think that the problem lies in `Action._popen` in the `session.py` module,
where `self.session.popen` is called (line 216).
popen is run with the `shell` keyword argument set to `False`, and causes the
command to fall over on Windows.
Since I had already noticed that problem (on Windows only) in other places
where I use `subprocess`, I tried to change the value to `True` by doing
return self.session.popen(args, shell=(sys.platform == 'win32'),
cwd=str(cwd),
universal_newlines=True,
stdout=stdout, stderr=stderr,
env=env)
and that solved the issue (while keeping the default value to `False` on
non-Windows platforms).
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit