Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 1068e26

Browse files
committed
Determine args to pass to package_name.test() based on what arguments it actually takes.
This provides at least a temporary workaround to the issue I raised in this comment: astropy/astropy#3019 (comment) (It would be nicer if we also warned when unsupported options were passed to the test command, but that would require a little more reworking of this--this is good enough to at least ensure a degree of compatibility.)
1 parent 8c08dbb commit 1068e26

1 file changed

Lines changed: 41 additions & 18 deletions

File tree

‎astropy_helpers/test_helpers.py‎

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3+
import inspect
34
import os
45
import shutil
56
import subprocess
@@ -162,31 +163,23 @@ def run(self):
162163
'_save_coverage(cov, result, "{0}", "{1}");'.format(
163164
os.path.abspath('.'), testing_path))
164165

166+
test_args = filter(lambda arg: hasattr(self, arg),
167+
self._get_test_runner_args())
168+
169+
test_args = ', '.join('{0}={1!r}'.format(arg, getattr(self, arg))
170+
for arg in test_args)
171+
165172
if PY3:
166173
set_flag = "import builtins; builtins._ASTROPY_TEST_ = True"
167174
else:
168175
set_flag = "import __builtin__; __builtin__._ASTROPY_TEST_ = True"
169176

170-
cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = ('
171-
'{1.package_name}.test('
172-
'package={1.package!r}, '
173-
'test_path={1.test_path!r}, '
174-
'args={1.args!r}, '
175-
'plugins={1.plugins!r}, '
176-
'verbose={1.verbose_results!r}, '
177-
'pastebin={1.pastebin!r}, '
178-
'remote_data={1.remote_data!r}, '
179-
'pep8={1.pep8!r}, '
180-
'pdb={1.pdb!r}, '
181-
'open_files={1.open_files!r}, '
182-
'parallel={1.parallel!r}, '
183-
'docs_path={1.docs_path!r}, '
184-
'skip_docs={1.skip_docs!r}, '
185-
'repeat={1.repeat!r}));'
186-
'{cmd_post}'
177+
cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = '
178+
'{1.package_name}.test({test_args}); {cmd_post}'
187179
'sys.exit(result)')
188180

189-
cmd = cmd.format(set_flag, self, cmd_pre=cmd_pre, cmd_post=cmd_post)
181+
cmd = cmd.format(set_flag, self, cmd_pre=cmd_pre,
182+
cmd_post=cmd_post, test_args=test_args)
190183

191184
# Run the tests in a subprocess--this is necessary since
192185
# new extension modules may have appeared, and this is the
@@ -212,3 +205,33 @@ def run(self):
212205
shutil.rmtree(tmp_dir)
213206

214207
raise SystemExit(retcode)
208+
209+
def _get_test_runner_args(self):
210+
"""
211+
A hack to determine what arguments are supported by the package's
212+
test() function. In the future there should be a more straightforward
213+
API to determine this (really it should be determined by the
214+
``TestRunner`` class for whatever version of Astropy is in use).
215+
"""
216+
217+
if PY3:
218+
import builtins
219+
builtins._ASTROPY_TEST_ = True
220+
else:
221+
import __builtin__
222+
__builtin__._ASTROPY_TEST_ = True
223+
224+
try:
225+
pkg = __import__(self.package_name)
226+
if not hasattr(pkg, 'test'):
227+
raise ImportError(
228+
'package {0} does not have a {0}.test() function as '
229+
'required by the Astropy test runner'.format(package_name))
230+
231+
argspec = inspect.getargspec(pkg.test)
232+
return argspec.args
233+
finally:
234+
if PY3:
235+
del builtins._ASTROPY_TEST_
236+
else:
237+
del __builtin__._ASTROPY_TEST_

0 commit comments

Comments
 (0)