Thanks to Andreas Pelme for the suggestion.
See https://bitbucket.org/hpk42/pytest/src/17a246750c75f5eda01d065b9c72ab9fb0f1b544/_pytest/python.py?at=default#cl-1756 pytest's addfinalizer method appends finalizers to a list, and pops them off the end to call in finish(). These two lines must be switched to prevent _post_teardown accessing the blocking CursorWrapper. It's a bit ugly in this case, but you might want to use yield_fixtures to make the ordering more explicit: ``` @pytest.yield_fixture def django_db(_django_cursor_wrapper): if ('transactional_db' not in request.funcargnames and 'live_server' not in request.funcargnames and not is_django_unittest(request.node)): from django.test import TestCase with _django_cursor_wrapper: case = TestCase(methodName='__init__') case._pre_setup() yield case._post_teardown() yield ``` It looks pretty, except for that yield at the end, which is necessary when that if case is False.
monkey_patch_creation_for_db_suffix _get_test_db_name fix
Fix doc about test discovery
I had my tests in a file called tests.py and they weren't being discovered. I think py.test looks for files of the form test_*.py , and not test*.py; could you confirm that? (See last paragraph http://pytest.org/latest/goodpractises.html#python-test-discovery ) Another thing we could suggest is to set python_files=test*.py for this case.