Skip to content

Instantly share code, notes, and snippets.

@electrofelix
Last active December 15, 2015 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electrofelix/99431833bf1529ffa9ab to your computer and use it in GitHub Desktop.
Save electrofelix/99431833bf1529ffa9ab to your computer and use it in GitHub Desktop.
testscenarios/fixtures issue
virtualenv testscenarios-bug
source testscenarios-bug/bin/activate
pip install testtools testscenarios fixtures
cat <<EOF > test_bug.py
import os
import fixtures
import testscenarios
import testtools
class TestBug(testscenarios.TestWithScenarios,
testtools.TestCase):
scenarios = [
('s1', dict(v1=1, v2=1)),
('s2', dict(v1=1, v2=2))
]
def setUp(self):
super(TestBug, self).setUp()
self.tempdir = self.useFixture(fixtures.TempDir())
self.path = self.tempdir.path
self.addOnException(self.checktmpdir)
def checktmpdir(self, exc_info):
if not os.path.exists(self.path):
# this occurs for the failing test, which makes it very
# difficult to get info from a TempDir fixture *only* when the
# test fails. Almost as though the cleanup is called before
# the addOnException get's called.
print("%s: Bug hit! Directory '%s' should still exist" %
(self.__class__.__name__, self.path))
else:
print("%s: Directory '%s' still exists" %
(self.__class__.__name__, self.path))
def test_run(self):
self.assertEquals(self.v1, self.v2)
class TestBugWorking(testtools.TestCase):
def setUp(self):
super(TestBugWorking, self).setUp()
self.tempdir = self.useFixture(fixtures.TempDir())
self.path = self.tempdir.path
self.addOnException(self.checktmpdir)
def checktmpdir(self, exc_info):
if not os.path.exists(self.path):
print("%s: Bug hit! Directory '%s' should still exist" %
(self.__class__.__name__, self.path))
else:
# we only hit this for the failing test in a non-scenarios
# approach, which is as excepted here
print("%s: Directory '%s' still exists" %
(self.__class__.__name__, self.path))
def test_run_s1(self):
self.assertEquals(1, 1)
def test_run_s2(self):
self.assertEquals(1, 2)
EOF
python -m testtools.run discover -t .
Tests running...
TestBug: Bug hit! Directory '/tmp/tmpsDRKx3' should still exist
TestBug: Directory '/tmp/tmppBQSBt' still exists
TestBugWorking: Directory '/tmp/tmpL6yopi' still exists
======================================================================
FAIL: test_bug.TestBug.test_run(s2)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/dara/tmp/testbug/test_bug.py", line 36, in test_run
self.assertEquals(self.v1, self.v2)
File "/home/dara/tmp/testbug/testscenarios-bug/lib/python2.7/site-packages/testtools/testcase.py", line 350, in assertEqual
self.assertThat(observed, matcher, message)
File "/home/dara/tmp/testbug/testscenarios-bug/lib/python2.7/site-packages/testtools/testcase.py", line 435, in assertThat
raise mismatch_error
testtools.matchers._impl.MismatchError: 1 != 2
======================================================================
FAIL: test_bug.TestBugWorking.test_run_s2
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/dara/tmp/testbug/test_bug.py", line 62, in test_run_s2
self.assertEquals(1, 2)
File "/home/dara/tmp/testbug/testscenarios-bug/lib/python2.7/site-packages/testtools/testcase.py", line 350, in assertEqual
self.assertThat(observed, matcher, message)
File "/home/dara/tmp/testbug/testscenarios-bug/lib/python2.7/site-packages/testtools/testcase.py", line 435, in assertThat
raise mismatch_error
testtools.matchers._impl.MismatchError: 1 != 2
Ran 4 tests in 0.003s
FAILED (failures=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment