pytestconf.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 03 Mar 2010 19:20:03 +0100
changeset 4777 7e37cb866e97
parent 4766 162b2b127b15
child 4796 a20edc0f8b30
permissions -rw-r--r--
[test] check _shutting_down, not empty dict (empty dict test should go in pytestgc patch)

"""pytest configuration file: we need this to properly remove ressources
cached on test classes, at least until we've proper support for teardown_class
"""
import sys
from os.path import split, splitext
from logilab.common.pytest import PyTester

from cubicweb.etwist.server import _gc_debug

class CustomPyTester(PyTester):
    def testfile(self, filename, batchmode=False):
        try:
            return super(CustomPyTester, self).testfile(filename, batchmode)
        finally:
            modname = splitext(split(filename)[1])[0]
            for cls in vars(sys.modules[modname]).values():
                if getattr(cls, '__module__', None) != modname:
                    continue
                clean_repo_test_cls(cls)
            #_gc_debug()

def clean_repo_test_cls(cls):
    if 'repo' in cls.__dict__:
        if cls.repo._shutting_down:
            cls.repo.shutdown()
        del cls.repo
    for clsattr in ('cnx', '_orig_cnx', 'config', '_config', 'vreg', 'schema'):
        if clsattr in cls.__dict__:
            delattr(cls, clsattr)