tests/tools/conftest.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 28 Sep 2017 15:17:57 +0300
changeset 1832 0f1081928d65
parent 1809 3f0a552549d1
child 1850 614396cbffbf
permissions -rw-r--r--
fix wrong-import-order. first standard modules are imported, then others
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
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1809
diff changeset
    27
import time
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1809
diff changeset
    28
1808
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    29
import pytest
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    30
import xvfbwrapper
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    31
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
# 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
    33
sys.path.append(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    34
    os.path.abspath(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    35
        os.path.join(
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    36
            os.path.dirname(__file__), '..', '..')
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
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    42
# 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
    43
# 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
    44
# pytest returns error message:
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    45
# 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
    46
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    47
# 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
    48
# but they aren't.
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    49
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
# 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
    51
# $ 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
    52
# $ 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
    53
# $ 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
    54
# $ pkill -9 Xvfb
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    56
# 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
    57
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    58
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    59
# vdisplay = None
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    60
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
# @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
    62
# 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
    63
#     global vdisplay
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
#     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
    65
#     vdisplay.start()
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    66
#     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
    67
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
# def stop_xvfb_server():
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
#     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
    70
#         vdisplay.stop()