From 751b62e344d85baf8182565425d79be230a08d78 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 2 Apr 2015 19:05:20 -0300 Subject: [PATCH] Moving logging and QApplication to conftest As discussed in #8 --- qutebrowser/test/__init__.py | 15 ---------- qutebrowser/test/conftest.py | 32 ++++++++++++++++++++++ qutebrowser/test/utils/test_standarddir.py | 18 ++++++------ tox.ini | 3 ++ 4 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 qutebrowser/test/conftest.py diff --git a/qutebrowser/test/__init__.py b/qutebrowser/test/__init__.py index 938eb6db3..cdb45eecc 100644 --- a/qutebrowser/test/__init__.py +++ b/qutebrowser/test/__init__.py @@ -18,18 +18,3 @@ # along with qutebrowser. If not, see . """The qutebrowser test suite.""" - -import atexit - -from PyQt5.QtWidgets import QApplication - -from qutebrowser.test import log - -# We create a singleton QApplication here. - -qApp = QApplication([]) -qApp.setApplicationName('qutebrowser') -qApp.processEvents() -atexit.register(qApp.processEvents) -atexit.register(qApp.quit) -log.init() diff --git a/qutebrowser/test/conftest.py b/qutebrowser/test/conftest.py new file mode 100644 index 000000000..93287d046 --- /dev/null +++ b/qutebrowser/test/conftest.py @@ -0,0 +1,32 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2015 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""The qutebrowser test suite contest file.""" + +import pytest + + +@pytest.fixture(scope='session', autouse=True) +def app_and_logging(qapp): + """ + Initializes our logging system and ensures that a QApplication is created + and used by all tests. + """ + from .log import init + init() diff --git a/qutebrowser/test/utils/test_standarddir.py b/qutebrowser/test/utils/test_standarddir.py index 8703eed5d..b2008135b 100644 --- a/qutebrowser/test/utils/test_standarddir.py +++ b/qutebrowser/test/utils/test_standarddir.py @@ -26,12 +26,13 @@ import shutil import unittest import tempfile +from PyQt5.QtWidgets import QApplication + from qutebrowser.utils import standarddir -from qutebrowser.test import helpers, qApp +from qutebrowser.test import helpers class GetStandardDirLinuxTests(unittest.TestCase): - """Tests for standarddir under Linux. Attributes: @@ -41,8 +42,8 @@ class GetStandardDirLinuxTests(unittest.TestCase): def setUp(self): self.temp_dir = tempfile.mkdtemp() - self.old_name = qApp.applicationName() - qApp.setApplicationName('qutebrowser') + self.old_name = QApplication.instance().applicationName() + QApplication.instance().setApplicationName('qutebrowser') @unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux") def test_data_explicit(self): @@ -97,12 +98,11 @@ class GetStandardDirLinuxTests(unittest.TestCase): self.assertEqual(standarddir.cache(), expected) def tearDown(self): - qApp.setApplicationName(self.old_name) + QApplication.instance().setApplicationName(self.old_name) shutil.rmtree(self.temp_dir) class GetStandardDirWindowsTests(unittest.TestCase): - """Tests for standarddir under Windows. Attributes: @@ -110,13 +110,13 @@ class GetStandardDirWindowsTests(unittest.TestCase): """ def setUp(self): - self.old_name = qApp.applicationName() + self.old_name = QApplication.instance().applicationName() # We can't store the files in a temp dir, so we don't chose qutebrowser - qApp.setApplicationName('qutebrowser_test') + QApplication.instance().setApplicationName('qutebrowser_test') standarddir.init(None) def tearDown(self): - qApp.setApplicationName(self.old_name) + QApplication.instance().setApplicationName(self.old_name) @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") def test_data(self): diff --git a/tox.ini b/tox.ini index 994f2b089..18d5e0529 100644 --- a/tox.ini +++ b/tox.ini @@ -103,3 +103,6 @@ commands = {envpython} scripts/src2asciidoc.py git --no-pager diff --exit-code --stat {envpython} scripts/asciidoc2html.py {posargs} + +[pytest] +norecursedirs = .tox .venv