-
-
Notifications
You must be signed in to change notification settings - Fork 361
run_local not working on windows #411
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
Comments
Thanks, from @jacobEAdamson comments in the pull request and seeing here you mention python 3.7 things are a little more clear, and a little more confused.
So that explains the error above, but this raises more questions for me ... It looks like this happened originally with 4ab331a which gives the clue it was related to something like ISO-8859-15 systems and a command like
I think maybe the problem was that you're calling Popen("ssh remotehost ls -l /é") and so Popen encodes the "/é" for the local system (https://github.com/python/cpython/blob/v3.7.3/Lib/subprocess.py#L1436) but then that is incorrect when the remote is running something like ISO-8859-15, and it now gets a (say) UTF-8 encoded command-line to try and run? So by making it a bytes-like object you short-circuit python trying to encode for you? Then there's a bunch of suff about CreateProcessA and CreateProcessW on windows that suggests that running commands should either be an ascii string or UTF-16 chars. Then I just get lost ... :) |
Same problem. Only python 2.7 seems to work. I've tried 3.5 and 3.7 as well and got the above mentioned: |
Similar problem. Windows 2008 r2 + Python 3.8.3 + testinfra 5.2.1.
The workaround for me is a runtime method patching removing the |
Hey Vinicius,
Can you show me how you did this? I've tried a lot of things now, but I did not succeed. This is my test_infra.py file:
But when running the test via
I still get
How did you patch the |
In my conftest.py:
|
@viniciusartur solution wasn't suffisent in my case (I'm using testinfra with docker backend), but combining its solution with #375 (comment) made it work : # conftest.py
import os
import re
import subprocess
import testinfra
def patch_testinfra():
if os.name == 'nt':
"""
Making testinfa work from Windows with Docker backend.
Inspired from
- https://github.com/pytest-dev/pytest-testinfra/issues/411#issuecomment-782729362
- https://github.com/pytest-dev/pytest-testinfra/issues/375#issue-360991022
"""
def quote(command, *args):
def anon_1(arg):
if re.match(r'/("|\s|\')', arg) != None:
return arg
arg = re.sub('"', '\"', arg)
return '"%s"' % (arg)
if args:
return command % tuple(anon_1(a) for a in args)
# return command % tuple(pipes.quote(a) for a in args)
return command
def run_local_new(self, command, *args):
command = quote(command, *args)
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
from testinfra.backend.base import BaseBackend
BaseBackend.run_local = run_local_new
def pytest_generate_tests(metafunc):
patch_testinfra() |
Uh oh!
There was an error while loading. Please reload this page.
My 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:
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:
Basically only encode when not on windows
The text was updated successfully, but these errors were encountered: