diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 8fb15158221d65..d8c500e488a060 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -21,12 +21,6 @@ import test.support import test.script_helper -try: - import stackless - usingStackless = True -except ImportError: - usingStackless = False - # Skip tests if _multiprocessing wasn't built. _multiprocessing = test.support.import_module('_multiprocessing') @@ -1858,7 +1852,7 @@ def errback(exc): p.close() p.join() - @unittest.skipIf(usingStackless, "Stackless can pickle lambdas") + @unittest.skipIf(test.support.stackless, "Stackless can pickle lambdas") def test_unpickleable_result(self): from multiprocessing.pool import MaybeEncodingError p = multiprocessing.Pool(2) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 9ac1abc9c4cc84..6ab86a434d9802 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -11,7 +11,7 @@ from test.support import ( TestFailed, TESTFN, run_with_locale, no_tracing, - _2G, _4G, bigmemtest, + _2G, _4G, bigmemtest, stackless, ) from pickle import bytes_types @@ -400,12 +400,11 @@ def create_dynamic_class(name, bases): # xrange(5) pickled from 2.x with protocol 2 DATA4 = b'\x80\x02c__builtin__\nxrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02.' -try: - import stackless +if stackless: DATA4_SLP = b'\x80\x02cstackless._wrap\nrange\nq\x00K\x00K\x05K\x01\x87q\x01Rq\x02)b.' -except: +else: DATA4_SLP = DATA4 - + # a SimpleCookie() object pickled from 2.x with protocol 2 DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key' @@ -1285,9 +1284,7 @@ def test_unpickle_from_2x(self): loaded = self.loads(DATA3) self.assertEqual(loaded, set([1, 2])) loaded = self.loads(DATA4_SLP) - try: - import stackless - except ImportError: + if not stackless: self.assertEqual(type(loaded), type(range(0))) else: pass # stackless provides a fake range for unpickling diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index d98068cac8a638..7db96d916a7bb4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -28,6 +28,11 @@ import urllib.error import warnings +try: + import stackless +except ImportError: + stackless = None + try: import _thread, threading except ImportError: diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py index 6bdbd3c593d4f7..c3b4fd76317d0f 100644 --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -3,6 +3,7 @@ import warnings import os from platform import system as platform_system +from test.support import stackless class ExceptionClassTests(unittest.TestCase): @@ -31,11 +32,6 @@ def test_inheritance(self): inheritance_tree = open(os.path.join(os.path.split(__file__)[0], 'exception_hierarchy.txt')) - try: - import stackless - haveStackless = True - except: - haveStackless = False try: superclass_name = inheritance_tree.readline().rstrip() try: @@ -61,7 +57,7 @@ def test_inheritance(self): if '[' in exc_name: left_bracket = exc_name.index('[') exc_name = exc_name[:left_bracket-1] # cover space - if not haveStackless and exc_name == "TaskletExit": + if stackless is None and exc_name == "TaskletExit": exc_set.discard(exc_name) continue try: diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index df1957a7d13f5e..e7668a7dca38a1 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -20,12 +20,6 @@ except ImportError: has_c_implementation = False -try: - import stackless - has_stackless = True -except ImportError: - has_stackless = False - class PickleTests(AbstractPickleModuleTests): pass @@ -153,7 +147,7 @@ class SizeofTests(unittest.TestCase): def test_pickler(self): basesize = support.calcobjsize('5P2n3i2n3iP' + - ('P' if has_stackless else '')) + ('P' if support.stackless else '')) p = _pickle.Pickler(io.BytesIO()) self.assertEqual(object.__sizeof__(p), basesize) MT_size = struct.calcsize('3nP0n') diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 6606902dce46b5..55b5eb9e0484ea 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -806,11 +806,7 @@ def inner(): import collections check(collections.defaultdict.default_factory, size('3PP')) # wrapper_descriptor (descriptor object) - try: - import stackless - slxtra = 'i' - except: - slxtra = '' + slxtra = 'i' if test.support.stackless else '' check(int.__add__, size('3P2P' + slxtra)) # method-wrapper (descriptor object) check({}.__iter__, size('2P')) @@ -859,11 +855,7 @@ class C(object): pass nfrees = len(x.f_code.co_freevars) extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\ ncells + nfrees - 1 - try: - import stackless - slextra = 'P' - except: - slextra = '' + slextra = 'P' if test.support.stackless else '' check(x, vsize('12P3ic' + CO_MAXBLOCKS*'3i' + slextra + 'P' + extras*'P')) # function def func(): pass diff --git a/Stackless/changelog.txt b/Stackless/changelog.txt index a36340104a0950..8ee8a469f04086 100644 --- a/Stackless/changelog.txt +++ b/Stackless/changelog.txt @@ -9,6 +9,10 @@ What's New in Stackless 3.X.X? *Release date: 20XX-XX-XX* +- https://bitbucket.org/stackless-dev/stackless/issues/126 + Load the module stackless early in all C-Python tests. This ensures a defined + behaviour of the tests even, if the execution order gets randomised. + - https://bitbucket.org/stackless-dev/stackless/issues/125 This document (changelog.txt) is included in the documentation as "What’s New in Stackless-Python ..."