Skip to content
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

Support for running setup.py nosetests #7

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions nosepipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ def __call__(self, result):
useshell = True

self.logger.debug("Executing %s", " ".join(argv))
popen = subprocess.Popen(argv,
cwd=self._cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=useshell,
)
try:
popen = subprocess.Popen(argv,
cwd=self._cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=useshell,
)
except OSError as e:
raise Exception("Error running %s [%s]" % (argv[0], e))

try:
stdout = popen.stdout
while True:
Expand Down Expand Up @@ -191,18 +195,44 @@ def __init__(self):
nose.plugins.Plugin.__init__(self)
self._test = None
self._test_proxy = None
self._argv = [os.path.abspath(sys.argv[0]),
'--with-process-isolation-reporter']
self._argv += ProcessIsolationPlugin._get_nose_whitelisted_argv()

# Normally, nose is called as:
# nosetests {opt1} {opt2} ...
# However, we can also be run as:
# setup.py nosetests {opt1} {opt2} ...
# When not running directly as nosetests, we need to run the
# sub-processes as `nosetests`, not `setup.py nosetests` as the output
# of setup.py interferes with the nose output. So, we need to find
# where nosetests is on the command-line and then run the
# sub-processes command-line using the args from that location.

nosetests_index = None
# Find where nosetests is in argv and start the new argv from there.
for i in range(0, len(sys.argv)):
if 'nosetests' in sys.argv[i]:
self._argv = [sys.argv[i]]
nosetests_index = i
break

if nosetests_index is None:
raise Exception("nosetests not found in command-line")

self._argv += ['--with-process-isolation-reporter']
# add the rest of the args that appear in argv after `nosetests`
self._argv += ProcessIsolationPlugin._get_nose_whitelisted_argv(
offset=nosetests_index + 1)
# Getting cwd inside SubprocessTestProxy.__call__ is too late - it is
# already changed by nose
self._cwd = os.getcwd()

@staticmethod
def _get_nose_whitelisted_argv():
def _get_nose_whitelisted_argv(offset=1):
# This is the list of nose options which should be passed through to
# the launched process; boolean value defines whether the option
# takes a value or not.
#
# offset: int, the argv index of the first nosetests option.
#
whitelist = {
'--debug-log': True,
'--logging-config': True,
Expand All @@ -228,7 +258,7 @@ def _get_nose_whitelisted_argv():
'--doctest-options': True,
'--no-skip': False,
}
filtered = set(whitelist.keys()).intersection(set(sys.argv[1:]))
filtered = set(whitelist.keys()).intersection(set(sys.argv[offset:]))
result = []
for key in filtered:
result.append(key)
Expand All @@ -237,7 +267,7 @@ def _get_nose_whitelisted_argv():

# We are not finished yet: options with '=' were not handled
whitelist_keyval = [(k + "=") for k, v in whitelist.items() if v]
for arg in sys.argv[1:]:
for arg in sys.argv[offset:]:
for keyval in whitelist_keyval:
if arg.startswith(keyval):
result.append(arg)
Expand Down