tests/tools/conftest.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 19 Oct 2017 11:03:03 +0300
changeset 1878 fb73a6b6622d
parent 1850 614396cbffbf
child 1881 091005ec69c4
permissions -rw-r--r--
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
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
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    28
# import pytest
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    29
# import xvfbwrapper
1808
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
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    32
def init_environment():
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    33
    """Append module root directory to sys.path"""
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    34
    try:
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    35
        import Beremiz as _Beremiz
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    36
    except ImportError:
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    37
        sys.path.append(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    38
            os.path.abspath(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    39
                os.path.join(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    40
                    os.path.dirname(__file__), '..', '..')
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    41
            )
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    42
        )
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    43
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    44
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    45
init_environment()
1808
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
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    48
# 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
    49
# 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
    50
# pytest returns error message:
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    51
# 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
    52
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
# 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
    54
# but they aren't.
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
# 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
    57
# $ 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
    58
# $ 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
    59
# $ 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
    60
# $ pkill -9 Xvfb
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    61
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    62
# 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
    63
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    64
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    65
# vdisplay = None
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
# @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
    68
# 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
    69
#     global vdisplay
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    70
#     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
    71
#     vdisplay.start()
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
#     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
    73
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
# def stop_xvfb_server():
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    75
#     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
    76
#         vdisplay.stop()