Created
December 20, 2012 15:15
-
-
Save schmir/4345862 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env py.test | |
import pytest | |
class Client(object): | |
def __init__(self, url): | |
self.usable = True | |
self.url = url | |
def __repr__(self): | |
return "Client %r" % self.__dict__ | |
@pytest.fixture(params=["amqp://"]) | |
def amqp_url(request): | |
"""the URL to a running rabbitmq instance""" | |
return request.param | |
@pytest.fixture | |
def qname(request, client): | |
def cleanup(): | |
print "CLEANUP QNAME", client | |
assert client.usable | |
request.addfinalizer(cleanup) | |
return "foo" | |
@pytest.fixture | |
def client(request, amqp_url): | |
"""a connected puka.Client instance""" | |
retval = Client(amqp_url) | |
def cleanup(): | |
retval.usable = False | |
print "CLEANUP CLIENT" | |
request.addfinalizer(cleanup) | |
return retval | |
def test_baz(client, qname): | |
print "hello", client | |
# Output is something like: | |
# [dev] ~/ % ./pytest-cleanup-order.py | |
# ============================== test session starts =============================== | |
# platform linux2 -- Python 2.7.3 -- pytest-2.3.4 | |
# plugins: xdist | |
# collected 1 items | |
# pytest-cleanup-order.py .E | |
# ===================================== ERRORS ===================================== | |
# _____________________ ERROR at teardown of test_baz[amqp://] _____________________ | |
# def cleanup(): | |
# print "CLEANUP QNAME", client | |
# > assert client.usable | |
# E assert Client {'url': 'amqp://', 'usable': False}.usable | |
# pytest-cleanup-order.py:21: AssertionError | |
# -------------------------------- Captured stdout --------------------------------- | |
# hello Client {'url': 'amqp://', 'usable': True} | |
# CLEANUP CLIENT | |
# CLEANUP QNAME Client {'url': 'amqp://', 'usable': False} | |
# ======================= 1 passed, 1 error in 0.01 seconds ======================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment