Skip to content

Commit 1f0db09

Browse files
author
Anselm Kruis
committed
Issue python#116: Test suite: use test.regrtest as test driver in runAll.py
Change Stackless/unittests/runAll.py to use the test driver of the C-Python test suite. Now we can use all CPython test suite options with Stackless too. https://bitbucket.org/stackless-dev/stackless/issues/116 (grafted from 28757ff577e0a8b796ef33c9ffb31f6372ba222f)
1 parent 851b549 commit 1f0db09

18 files changed

Lines changed: 69 additions & 6 deletions

Stackless/unittests/runAll.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
"""
22
runAll.py
33
4-
Runs all testcases in files named test_*.py.
4+
Runs all test-cases in files named test_*.py.
55
Should be run in the folder Stackless/unittests.
6+
7+
This driver reuses the CPython test.regrtest driver and
8+
supports its options.
69
"""
10+
from __future__ import absolute_import
711

812
import os
9-
import unittest
13+
# just to make sure, it can be imported
14+
import support # @UnusedImport
15+
16+
from test import regrtest
17+
from test import __path__ as test_path
18+
19+
# path of the Stackless unittest directory
20+
path = os.path.split(__file__)[0]
21+
# add the stackless unittest dir to the package "test"
22+
test_path.insert(0, path)
23+
24+
# monkey patch: remove all standard tests
25+
del regrtest.STDTESTS[:]
1026

1127

1228
def main():
13-
path = os.path.split(__file__)[0]
14-
print(path)
15-
testSuite = unittest.TestLoader().discover(path)
16-
unittest.TextTestRunner(verbosity=2).run(testSuite)
29+
return regrtest.main(testdir=path)
1730

1831
if __name__ == '__main__':
1932
main()

Stackless/unittests/support.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io
3333
import contextlib
3434
import gc
35+
from test.support import run_unittest
3536

3637
# emit warnings about uncollectable objects
3738
gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
@@ -444,3 +445,23 @@ def helper():
444445
result = c.receive()
445446
assert self._ran_AsTaskletTestCase_setUp
446447
return result
448+
449+
450+
def test_main():
451+
"""Main function for the CPython :mod:`test.regrtest` test driver.
452+
453+
Import this function into your test_ module. It uses introspection
454+
to find the module name and run your tests.
455+
"""
456+
stack = inspect.stack(0)
457+
for i in range(1, 5):
458+
try:
459+
the_module = stack[i][0].f_locals["the_module"]
460+
break
461+
except KeyError:
462+
pass
463+
else:
464+
raise RuntimeError("can't find local variable 'the_module'")
465+
466+
test_suite = unittest.TestLoader().loadTestsFromModule(the_module)
467+
return run_unittest(test_suite)

Stackless/unittests/test_chan_cb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import absolute_import
12
import unittest
23

34
from support import StacklessTestCase
5+
from support import test_main # @UnusedImport
46

57

68
class ChannelMonitor:

Stackless/unittests/test_channel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import absolute_import
12
import unittest
23
import stackless
34
try:
@@ -8,6 +9,7 @@
89
import sys
910
import traceback
1011
import contextlib
12+
from support import test_main # @UnusedImport
1113
from support import StacklessTestCase, require_one_thread
1214

1315

Stackless/unittests/test_defects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
withThreads = False
1414

1515
from stackless import _test_nostacklesscall as apply_not_stackless
16+
from support import test_main # @UnusedImport
1617
from support import StacklessTestCase, captured_stderr, require_one_thread
1718

1819

Stackless/unittests/test_exception.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import absolute_import
12
import unittest
23

4+
from support import test_main # @UnusedImport
35
from support import StacklessTestCase
46

57

Stackless/unittests/test_generator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from __future__ import absolute_import
12
import unittest
23
import gc
34
import stackless
45
import types
56

7+
from support import test_main # @UnusedImport
68
from support import StacklessTestCase
79

810

Stackless/unittests/test_miscell.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import absolute_import
12
# import common
23

34
import unittest
@@ -18,6 +19,7 @@
1819
except:
1920
withThreads = False
2021

22+
from support import test_main # @UnusedImport
2123
from support import StacklessTestCase, AsTaskletTestCase, require_one_thread
2224

2325

Stackless/unittests/test_outside.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from __future__ import absolute_import
12
import unittest
23
from stackless import test_cframe, test_cframe_nr, test_outside, test_cstate
34
from stackless import tasklet, channel, run
45

6+
from support import test_main # @UnusedImport
57
from support import StacklessTestCase
68

79

Stackless/unittests/test_pickle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from stackless import schedule, tasklet, stackless
88

9+
from support import test_main # @UnusedImport
910
from support import StacklessTestCase, StacklessPickleTestCase
1011

1112

0 commit comments

Comments
 (0)