pytestconf.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 31 Mar 2010 09:55:19 +0200
branchstable
changeset 5093 8d073d2e089d
parent 4804 daa71eaf11e8
child 5158 5e9055b8c10a
child 5421 8167de96c523
permissions -rw-r--r--
[optimization] improve massive write performance by optimizing hooks selection profiling on some massive deletion showed up that 2/3 of the time was spent in hooks selection. Those changes make it much more acceptable (through selection is still not negligeable): * use one registry for each event, so we've much less hooks to check when emiting an event as well as no more need for the match_event selector. This required ability to put one appobject into several registries, using a __registries__ class attribute. * check for deprecated .enabled at registry initialization time instead of at selection time A very simple HooksManager class has been reintroduce to choose the right registry on call_hooks. Those optimisations leads to a ~x3 factor of time necessary to delete 16000 entities.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
"""pytest configuration file: we need this to properly remove ressources
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
cached on test classes, at least until we've proper support for teardown_class
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
"""
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
import sys
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
from os.path import split, splitext
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
from logilab.common.pytest import PyTester
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
from cubicweb.etwist.server import _gc_debug
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
class CustomPyTester(PyTester):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    def testfile(self, filename, batchmode=False):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
        try:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
            return super(CustomPyTester, self).testfile(filename, batchmode)
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
        finally:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
            modname = splitext(split(filename)[1])[0]
4804
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    16
            try:
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    17
                module = sys.modules[modname]
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    18
            except KeyError:
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    19
                # error during test module import
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    20
                return
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    21
            for cls in vars(module).values():
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
                if getattr(cls, '__module__', None) != modname:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
                    continue
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
                clean_repo_test_cls(cls)
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
            #_gc_debug()
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
def clean_repo_test_cls(cls):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    if 'repo' in cls.__dict__:
4796
a20edc0f8b30 oops, 'not' missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4777
diff changeset
    29
        if not cls.repo._shutting_down:
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
            cls.repo.shutdown()
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
        del cls.repo
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
    for clsattr in ('cnx', '_orig_cnx', 'config', '_config', 'vreg', 'schema'):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
        if clsattr in cls.__dict__:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
            delattr(cls, clsattr)