run_local not working on windows
See original GitHub issueMy system is Python 3.7.0 running Windows 10 and I receive an error when I try to run anything with run_local on windows (which affects all backends). The stack trace looks like this:
venv\lib\site-packages\testinfra\host.py:71: in run
return self.backend.run(command, *args, **kwargs)
venv\lib\site-packages\testinfra\backend\docker.py:35: in run
"docker exec %s /bin/sh -c %s", self.name, cmd)
venv\lib\site-packages\testinfra\backend\base.py:203: in run_local
stderr=subprocess.PIPE,
..\..\..\appdata\local\programs\python\python37-32\Lib\subprocess.py:756: in __init__
restore_signals, start_new_session)
..\..\..\appdata\local\programs\python\python37-32\Lib\subprocess.py:1100: in _execute_child
args = list2cmdline(args)
..\..\..\appdata\local\programs\python\python37-32\Lib\subprocess.py:511: TypeError
TypeError: argument of type 'int' is not iterable
Looks like the fact that the command is being encoded before running is to blame. Popen in Windows doesn’t handle byte arrays the same way it does on Linux. Was able to fix by modifying code to this:
def run_local(self, command, *args):
command = self.quote(command, *args)
if os.name != 'nt':
command = self.encode(command)
p = subprocess.Popen(
command, shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
result = self.result(p.returncode, command, stdout, stderr)
return result
Basically only encode when not on windows
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
npm run local binaries on windows - Stack Overflow
How can you run local npm binaries on Windows(10)?. I'm trying to run a webpack dev-server(using webpack-encore in this instance)
Read more >Can't run local command on Windows - Julia Discourse
Something in the PATH works (e.g.): run(`git submodule update --init --recursive $smName`) where smName is a string defined previously.
Read more >Not able to run local dispatcher on Windows 10 Pro
Solved: Hi Guys, Getting error "Required image not found, trying to load from archive... unsupported os linux" when tried setting - 414480.
Read more >Running locally installed npm executables - 2ality
This blog post explains how to run locally installed executables. ... That directory node_modules/ may or may not exist, already; ...
Read more >Work with Azure Functions Core Tools | Microsoft Learn
Learn how to code and test Azure Functions from the command prompt or terminal on your local computer before you run them on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my conftest.py:
@viniciusartur solution wasn’t suffisent in my case (I’m using testinfra with docker backend), but combining its solution with https://github.com/pytest-dev/pytest-testinfra/issues/375#issue-360991022 made it work :