Source

pida-hacks / conftest.py

Full commit

import py
import pytest

import gtk
from pygtkhelpers.utils import refresh_gui

from tests.support import GladeFile, UidefFile

from pida.core import environment


collect_ignore = [
    'tools/skeleton',
    'tools/glade3-plugin',
    'externals',
    'build',
    'dist',
    'deb_dist',
]

@pytest.mark.tryfirst
def pytest_runtest_setup(item):
    settings_root = pytest.ensuretemp('homes')
    home = py.path.local.make_numbered_dir(
        prefix=item.name,
        rootdir=settings_root,
        lock_timeout=9,
    )
    environment.set_home(home)


def pytest_collect_file(path, parent):
    if path.check(ext='.glade'):
        return GladeFile(path, parent)
    if path.check(ext='.xml') and \
       path.dirpath().basename == 'uidef':
        return UidefFile(path, parent)

@pytest.mark.last
def pytest_runtest_teardown():
    for toplevel in gtk.window_list_toplevels():
        toplevel.destroy()
    refresh_gui()