tests/tools/conftest.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 08 May 2020 16:47:52 +0200
branchsvghmi
changeset 2948 faaf677ea99d
parent 1881 091005ec69c4
permissions -rw-r--r--
SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
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
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    25
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    26
from __future__ import absolute_import
1808
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    27
import os
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    28
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
    29
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    30
# import pytest
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    31
# import xvfbwrapper
1808
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    32
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    33
1850
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    34
def init_environment():
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    35
    """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
    36
    try:
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    37
        import Beremiz as _Beremiz
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    38
    except ImportError:
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    39
        sys.path.append(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    40
            os.path.abspath(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    41
                os.path.join(
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    42
                    os.path.dirname(__file__), '..', '..')
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
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    46
614396cbffbf fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
    47
init_environment()
1808
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
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    50
# 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
    51
# 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
    52
# pytest returns error message:
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    53
# 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
    54
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    55
# 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
    56
# but they aren't.
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
# 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
    59
# $ 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
    60
# $ 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
    61
# $ 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
    62
# $ pkill -9 Xvfb
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
# 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
    65
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
# vdisplay = None
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    68
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    69
# @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
    70
# 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
    71
#     global vdisplay
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    72
#     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
    73
#     vdisplay.start()
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    74
#     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
    75
#
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    76
# def stop_xvfb_server():
b4764ebb352d move configuration for test environment into separate file conftest.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff changeset
    77
#     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
    78
#         vdisplay.stop()