1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| | Make it so the test script included in the contextlib2 tarball will be run
when setup.py is invoked with the "test" target. Succeed if and only if the
tests pass.
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,36 @@
#!/usr/bin/env python
+import subprocess
+import sys
+
from distutils.core import setup
+from distutils.cmd import Command
+
+
+class TestRunner(Command):
+ description = "run the test script"
+ # distutils requires that user_options be set, but we don't actually need
+ # to create any special options for this command, so we use an empty list.
+ user_options = []
+ def initialize_options(self):
+ # All Command subclasses are required to implement this method,
+ # but we don't actually need to set up any options for this command.
+ pass
+
+ def finalize_options(self):
+ # Same as above.
+ pass
+
+ def run(self):
+ # The absolute path to the executable file for the currently
+ # running Python interpreter is in sys.executable. Let's just
+ # use that to invoke the tests like someone might from the
+ # shell. If the tests fail, this method call will raise an
+ # exception. The exception will not be caught, so it will cause
+ # the current Python interpreter to print a stack trace and exit
+ # with a non-zero exit code. The test output will go to
+ # stdout/stderr regardless of whether the tests succeed or fail.
+ subprocess.check_call([sys.executable, "./test_contextlib2.py", "-v"])
+
# Technically, unittest2 is a dependency to run the tests on 2.6 and 3.1
# This file ignores that, since I don't want to depend on distribute
@@ -10,6 +41,7 @@ setup(
version=open('VERSION.txt').read().strip(),
py_modules=['contextlib2'],
license='PSF License',
+ cmdclass={'test': TestRunner},
description='Backports and enhancements for the contextlib module',
long_description=open('README.txt').read(),
author='Nick Coghlan',
|