tests/tools/conftest.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 28 Sep 2017 12:20:40 +0300
changeset 1831 56b48961cc68
parent 1809 3f0a552549d1
child 1832 0f1081928d65
permissions -rw-r--r--
fix (old-style-class) Old-style class defined error for most parts of
the code

only PyJS code is left, because it does some fancy tricks and can't be
easily fixed. So far PyJS doesn't support Python3 anyway.
1808
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     3
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     6
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     7
# Copyright (C) 2017: Andrey Skvortsov
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     8
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
     9
# See COPYING file for copyrights details.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    10
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    11
# This program is free software; you can redistribute it and/or
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    12
# modify it under the terms of the GNU General Public License
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    13
# as published by the Free Software Foundation; either version 2
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    14
# of the License, or (at your option) any later version.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    15
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    16
# This program is distributed in the hope that it will be useful,
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    19
# GNU General Public License for more details.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    20
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    21
# You should have received a copy of the GNU General Public License
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    22
# along with this program; if not, write to the Free Software
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    24
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    25
import os
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    26
import sys
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    27
import pytest
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    28
import xvfbwrapper
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
import time
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
# append module root directory to sys.path
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
sys.path.append(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
    os.path.abspath(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
        os.path.join(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    35
            os.path.dirname(__file__), '..', '..')
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
    )
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    37
)
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    38
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    39
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    40
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    41
# Something seems to be broken in Beremiz application,
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
# because after tests in test_application.py during Xvfb shutdown
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    43
# pytest returns error message:
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    44
# pytest: Fatal IO error 11 (Die Ressource ist zur Zeit nicht verfügbar) on X server :2821.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    46
# As a result of that pytest returns code 1 as some tests were failed,
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
# but they aren't.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
# To avoid this Xvfb is launched and killed not by pytest.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
# $ Xvfb :42 -screen 0 1280x1024x24 &
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
# $ export DISPLAY=:42
1809
3f0a552549d1 run separate test on every project instead of one big long test all projects
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1808
diff changeset
    52
# $ pytest --timeout=10 ./tests/tools
1808
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
# $ pkill -9 Xvfb
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    54
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
# TODO: find root of this problem.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    57
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
# vdisplay = None
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
# @pytest.fixture(scope="session", autouse=True)
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
# def start_xvfb_server(request):
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
#     global vdisplay
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    63
#     vdisplay = xvfbwrapper.Xvfb(width=1280, height=720)
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
#     vdisplay.start()
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
#     request.addfinalizer(stop_xvfb_server)
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    67
# def stop_xvfb_server():
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
#     if vdisplay is not None:
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
#         vdisplay.stop()