Skip to content

Commit 259238e

Browse files
committed
Fix for the issue I originally mentioned in astropy#73 (comment); this is just a matter of porting the change originally made in 1068e26 to work in the v1.0 release series.
1 parent 7e3156b commit 259238e

1 file changed

Lines changed: 42 additions & 19 deletions

File tree

‎astropy_helpers/test_helpers.py‎

Lines changed: 42 additions & 19 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
@@ -99,30 +100,23 @@ def generate_testing_command(self):
99100
cmd_pre += pre
100101
cmd_post += post
101102

103+
test_args = filter(lambda arg: hasattr(self, arg),
104+
self._get_test_runner_args())
105+
106+
test_args = ', '.join('{0}={1!r}'.format(arg, getattr(self, arg))
107+
for arg in test_args)
108+
102109
if PY3:
103110
set_flag = "import builtins; builtins._ASTROPY_TEST_ = True"
104111
else:
105112
set_flag = "import __builtin__; __builtin__._ASTROPY_TEST_ = True"
106113

107-
cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = ('
108-
'{1.package_name}.test('
109-
'package={1.package!r}, '
110-
'test_path={1.test_path!r}, '
111-
'args={1.args!r}, '
112-
'plugins={1.plugins!r}, '
113-
'verbose={1.verbose_results!r}, '
114-
'pastebin={1.pastebin!r}, '
115-
'remote_data={1.remote_data!r}, '
116-
'pep8={1.pep8!r}, '
117-
'pdb={1.pdb!r}, '
118-
'open_files={1.open_files!r}, '
119-
'parallel={1.parallel!r}, '
120-
'docs_path={1.docs_path!r}, '
121-
'skip_docs={1.skip_docs!r}, '
122-
'repeat={1.repeat!r})); '
123-
'{cmd_post}'
114+
cmd = ('{cmd_pre}{0}; import {1.package_name}, sys; result = '
115+
'{1.package_name}.test({test_args}); {cmd_post}'
124116
'sys.exit(result)')
125-
return cmd.format(set_flag, self, cmd_pre=cmd_pre, cmd_post=cmd_post)
117+
118+
return cmd.format(set_flag, self, cmd_pre=cmd_pre,
119+
cmd_post=cmd_post, test_args=test_args)
126120

127121
def _validate_required_deps(self):
128122
"""
@@ -155,7 +149,6 @@ def run(self):
155149
try:
156150
# Construct this modules testing command
157151
cmd = self.generate_testing_command()
158-
159152
# Run the tests in a subprocess--this is necessary since
160153
# new extension modules may have appeared, and this is the
161154
# easiest way to set up a new environment
@@ -248,3 +241,33 @@ def _generate_coverage_commands(self):
248241
os.path.abspath('.'), self.testing_path))
249242

250243
return cmd_pre, cmd_post
244+
245+
def _get_test_runner_args(self):
246+
"""
247+
A hack to determine what arguments are supported by the package's
248+
test() function. In the future there should be a more straightforward
249+
API to determine this (really it should be determined by the
250+
``TestRunner`` class for whatever version of Astropy is in use).
251+
"""
252+
253+
if PY3:
254+
import builtins
255+
builtins._ASTROPY_TEST_ = True
256+
else:
257+
import __builtin__
258+
__builtin__._ASTROPY_TEST_ = True
259+
260+
try:
261+
pkg = __import__(self.package_name)
262+
if not hasattr(pkg, 'test'):
263+
raise ImportError(
264+
'package {0} does not have a {0}.test() function as '
265+
'required by the Astropy test runner'.format(package_name))
266+
267+
argspec = inspect.getargspec(pkg.test)
268+
return argspec.args
269+
finally:
270+
if PY3:
271+
del builtins._ASTROPY_TEST_
272+
else:
273+
del __builtin__._ASTROPY_TEST_

0 commit comments

Comments
 (0)