Last active
August 29, 2015 14:04
-
-
Save lukeorland/d4534a20241d7b5280b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from nose2.tools import such | |
def slow_blocking_init(): | |
time.sleep(1) | |
print("a second elapsed") | |
time.sleep(1) | |
print("a second elapsed") | |
return True | |
with such.A('system with a fast initial setup layer') as it: | |
@it.has_setup | |
def setup(): | |
it.obj = False | |
@it.should('not have obj initialized') | |
def test(): | |
assert not it.obj | |
with it.having('a second slow setup layer'): | |
@it.has_setup | |
def setup(): | |
it.obj = slow_blocking_init() | |
@it.should('have obj initialized') | |
def test(): | |
assert it.obj | |
it.createTests(globals()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from nose2.tools import such | |
def slow_blocking_init(): | |
time.sleep(1) | |
print("a second elapsed") | |
time.sleep(1) | |
print("a second elapsed") | |
return True | |
class Layer1(object): | |
@classmethod | |
def setUp(cls): | |
it.obj = False | |
class Layer2(object): | |
@classmethod | |
def setUp(cls): | |
it.obj = slow_blocking_init() | |
with such.A('system with a fast initial setup layer') as it: | |
it.uses(Layer1) | |
@it.should('not have obj initialized') | |
def test(): | |
assert not it.obj | |
with it.having('a second slow setup layer'): | |
it.uses(Layer2) | |
@it.should('have obj initialized') | |
def test(): | |
assert it.obj | |
it.createTests(globals()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import unittest | |
def slow_blocking_init(): | |
time.sleep(1) | |
print("a second elapsed") | |
time.sleep(1) | |
print("a second elapsed") | |
return True | |
class Layer1(object): | |
@classmethod | |
def setUp(cls): | |
cls.obj = False | |
class Layer2(Layer1): | |
@classmethod | |
def setUp(cls): | |
cls.obj = slow_blocking_init() | |
class TestCaseLayer1(unittest.TestCase): | |
layer = Layer1 | |
def test_initialized_obj(self): | |
assert not self.layer.obj | |
class TestCaseLayer2(unittest.TestCase): | |
layer = Layer2 | |
def test_slow_initialized_obj(self): | |
assert self.layer.obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
test_nose2_such
andtest_nose2_unittest_layers
versions execute the setups in the expected order...However, the
test_nose2_such_layers
version runs the Layer2 test cases before (or at the same time as?) executing the the Layer2 setup: