author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Mon, 01 Mar 2010 11:26:14 +0100 | |
changeset 4913 | 083b4d454192 |
parent 4804 | daa71eaf11e8 |
child 5158 | 5e9055b8c10a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
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) |