Skip to content

Instantly share code, notes, and snippets.

@Nitrodist

Nitrodist/output Secret

Created May 27, 2015 20:30
Show Gist options
  • Save Nitrodist/60ced9ca02d9e56cde42 to your computer and use it in GitHub Desktop.
Save Nitrodist/60ced9ca02d9e56cde42 to your computer and use it in GitHub Desktop.
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