Skip to content

Instantly share code, notes, and snippets.

@Nitrodist Nitrodist/output Secret
Created May 27, 2015

Embed
What would you like to do?
py.test -s test.py
================================= test session starts ==================================
platform darwin -- Python 2.7.9 -- py-1.4.27 -- pytest-2.6.4
collected 2 items
test.py
beginning
in passing test
.
rollback
beginning
in failing test
F
rollback
======================================= FAILURES =======================================
_________________________ TestMyWidget.test_my_failing_widget __________________________
self = <test.TestMyWidget instance at 0x10cd01cb0>
db_transaction = <test.Object object at 0x10ccfded0>
def test_my_failing_widget(self, db_transaction):
print "\nin failing test\n"
> raise Exception()
E Exception
test.py:39: Exception
========================== 1 failed, 1 passed in 0.01 seconds ==========================
class Object(object):
pass
orm = Object()
orm.session = Object()
def begin():
print "\nbeginning\n"
def rollback():
print "\nrollback\n"
orm.session.begin = begin
orm.session.rollback = rollback
import pytest
@pytest.fixture()
def db_transaction(request):
orm.session.begin()
def fin():
orm.session.rollback()
request.addfinalizer(fin)
return orm.session
class TestMyWidget:
def test_my_widget(self, db_transaction):
print "\nin passing test\n"
def test_my_failing_widget(self, db_transaction):
print "\nin failing test\n"
raise Exception()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.