From 74c1eb76e22f77fd7323602bf7e0fe4bdea6e52c Mon Sep 17 00:00:00 2001 From: Rafael de Lucena Valle Date: Wed, 14 Aug 2024 23:28:55 -0300 Subject: [PATCH] Remove references for nosetests --- README.rst | 6 +- client/doc/gkit_aliases.rst | 4 +- client/doc/launching_tests.rst | 48 ++---- client/doc/qml_tutorial.rst | 2 +- client/doc/tutorial.rst | 16 +- client/funq/noseplugin.py | 202 ------------------------- client/funq/tests/test_models.py | 2 + client/funq/tests/test_screenshoter.py | 1 - client/funq/tests/test_tools.py | 10 +- doc-dev/general.rst | 12 +- tests-functionnal/setup.cfg | 2 +- 11 files changed, 44 insertions(+), 261 deletions(-) delete mode 100644 client/funq/noseplugin.py diff --git a/README.rst b/README.rst index 67c2194..ec05c18 100644 --- a/README.rst +++ b/README.rst @@ -103,12 +103,12 @@ How does *funq* works - **funq** is a python package that offers an API to interact with a **libFunq** TCP server. It is the client side of the project, and uses - nosetests to launch FUNctional Qt tests. + pytest to launch FUNctional Qt tests. Compatibility ============= -Funq currently works with Python >= 3.5, Qt4 and Qt5 on GNU/Linux, macOS and +Funq currently works with Python >= 3.5, Qt5 and Qt6 on GNU/Linux, macOS and Windows. Documentation @@ -125,4 +125,6 @@ functional tests with **funq**. Thanks also to Jean-Luc Rouzoul, Dominique Constant and Mickaël Guérin for having supported this project. +Thanks to all the contributors for their patches, bug reports, and feedback. + Without them, **funq** would never have become a free software ! diff --git a/client/doc/gkit_aliases.rst b/client/doc/gkit_aliases.rst index c36f32b..90be410 100644 --- a/client/doc/gkit_aliases.rst +++ b/client/doc/gkit_aliases.rst @@ -23,8 +23,8 @@ You can use these aliases in the aliases file in a standard way (between {}). manager is used - **default** is always used. To use another graphical kit, you have to specify it with the *funq-gkit* - nose option. Example: + pytest option. Example: .. code-block:: bash - nosetests --with-funq --funq-gkit kde + pytest --with-funq --funq-gkit kde diff --git a/client/doc/launching_tests.rst b/client/doc/launching_tests.rst index 7f4c1c5..a9c224c 100644 --- a/client/doc/launching_tests.rst +++ b/client/doc/launching_tests.rst @@ -1,7 +1,7 @@ Launching tests (nose) ====================== -Tests are launched by `nose `_, +Tests are launched by `pytest `_, and you have to tell it to use the **funq** plugin. Manual launching @@ -9,82 +9,66 @@ Manual launching Basically:: - nosetests --with-funq + pytest --with-funq The command must be started from the folder containing tests files and the **funq.conf** configuration file. .. note:: - There are many options for nose, and some specifics to the **funq** - plugin. See ``nosetests --help`` for an exhaustive list. + There are many options for pytest, and some specifics to the **funq** + plugin. See ``pytest --help`` for an exhaustive list. Example:: # launch tests with all stdout/stderr output and stop on the first error - nosetests --with-funq -s -x + pytest --with-funq -s -x Defining default options ------------------------ -Every nose option may be specified by default in a file named **setup.cfg**. -You can look at the nose documentation for more informations. +Every pytest option may be specified by default in a file named **setup.cfg**. +You can look at the pytest documentation for more informations. Example: .. code-block:: ini - [nosetests] + [pytest] verbosity=2 with-funq=1 .. note:: - This configuration is very useful, and allow to type only **nosetests** - on the command line instead of ``nosetests --with-funq -vv``. I highly + This configuration is very useful, and allow to type only **pytest** + on the command line instead of ``pytest --with-funq -vv``. I highly recommend this configuration and I will use it in the following documentation. Selecting tests to launch ------------------------- -It s possible to select tests to launch using nose. +It s possible to select tests to launch using pytest. Example:: # every tests in a given file - nosetests test_export.py + pytest test_export.py # every tests of a given class in a test file - nosetests test_export.py:TestExportElectre + pytest test_export.py:TestExportElectre # just one test (one method) - nosetests test_export.py:TestExportElectre.test_export_b6 + pytest test_export.py:TestExportElectre.test_export_b6 .. note:: - See the nose documeation fo more information. + See the pytest documeation fo more information. If the verbosity option is equal to 2, the tests execution will show test names with the same format. This means that you can then copy/paste a test name to restart it. -Going further -------------- - -**nose** got plenty of usefuls plugins ! - -Some are integrated in nose, others are third-party plugins and need a -proper installation. - -Som of the interesting nose plugins are listed here: - -- **xunit**: format tests output using xunit -- **attributeselector**: select tests given their attributes -- **collect-only**: allow to only list tests without really execute them - -See the nose documentation, and google to find others usefuls plugins ! - .. note:: - It is also easy to write your own `nose plugins `_. + It is also easy to write your own `pytest plugins `_. diff --git a/client/doc/qml_tutorial.rst b/client/doc/qml_tutorial.rst index 47fca67..5126a3c 100644 --- a/client/doc/qml_tutorial.rst +++ b/client/doc/qml_tutorial.rst @@ -104,7 +104,7 @@ Run the test Just run:: - nosetests --with-funq + pytest --with-funq In the `qmltest` folder and watch it pass. diff --git a/client/doc/tutorial.rst b/client/doc/tutorial.rst index d31f60f..5644a59 100644 --- a/client/doc/tutorial.rst +++ b/client/doc/tutorial.rst @@ -32,7 +32,7 @@ And that funq is installed with: .. code-block:: bash - nosetests -h | grep 'with-funq' + pytest -h | grep 'with-funq' .. important:: @@ -90,7 +90,7 @@ Well done ! Let's run this first test. Type the following command: .. code-block:: bash - nosetests --with-funq + pytest --with-funq One window must appear, and close after a few seconds. The output on the terminal must look like this:: @@ -103,13 +103,13 @@ terminal must look like this:: .. note:: - The option ``--with-funq`` given to nosetests allow to use the funq plugin + The option ``--with-funq`` given to pytest allow to use the funq plugin that will read the configuration file and execute your tests. .. note:: - **nosetests** has multiples options to allow for example the generation - of an xml file to format tests result. See **nosetests -h**. + **pytest** has multiples options to allow for example the generation + of an xml file to format tests result. See **pytest -h**. And voilà! You have written and launched your first funq test. Now let's go a bit further by adding two tests and use an aliases file. @@ -159,7 +159,7 @@ Now you can start tests again: .. code-block:: bash - nosetests --with-funq + pytest --with-funq .. note:: @@ -170,7 +170,7 @@ Now you can start tests again: .. code-block:: bash - nosetests --with-funq test_widgets.py + pytest --with-funq test_widgets.py .. important:: @@ -178,7 +178,7 @@ Now you can start tests again: that depends on others tests. In other words, the *order of test execution must not be important*. This allow to limit side effects and to find quickly why a test failed. This being said, - **nosetests** does not assure any order in test execution. + **pytest** does not assure any order in test execution. Going further ------------- diff --git a/client/funq/noseplugin.py b/client/funq/noseplugin.py deleted file mode 100644 index e3690bd..0000000 --- a/client/funq/noseplugin.py +++ /dev/null @@ -1,202 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright: SCLE SFE -# Contributor: Julien Pagès -# -# This software is a computer program whose purpose is to test graphical -# applications written with the QT framework (http://qt.digia.com/). -# -# This software is governed by the CeCILL v2.1 license under French law and -# abiding by the rules of distribution of free software. You can use, -# modify and/ or redistribute the software under the terms of the CeCILL -# license as circulated by CEA, CNRS and INRIA at the following URL -# "http://www.cecill.info". -# -# As a counterpart to the access to the source code and rights to copy, -# modify and redistribute granted by the license, users are provided only -# with a limited warranty and the software's author, the holder of the -# economic rights, and the successive licensors have only limited -# liability. -# -# In this respect, the user's attention is drawn to the risks associated -# with loading, using, modifying and/or developing or reproducing the -# software by the user in light of its specific status of free software, -# that may mean that it is complicated to manipulate, and that also -# therefore means that it is reserved for developers and experienced -# professionals having in-depth computer knowledge. Users are therefore -# encouraged to load and test the software's suitability as regards their -# requirements in conditions enabling the security of their systems and/or -# data to be ensured and, more generally, to use and operate it in the -# same conditions as regards security. -# -# The fact that you are presently reading this means that you have had -# knowledge of the CeCILL v2.1 license and that you accept its terms. - -""" -Module that integrates funq with nosetests. -""" - -from funq.client import ApplicationRegistry -from funq.testcase import MultiFunqTestCase, FunqTestCase, \ - register_funq_app_registry -from funq.screenshoter import ScreenShoter -from funq import tools -from nose.plugins import Plugin -from configparser import ConfigParser -import os -import codecs -import logging - -LOG = logging.getLogger('nose.plugins.funq') - - -def message_with_sep(message): - """Returns a message with a separator.""" - sep = '-' * 70 - return (sep, message, sep) - - -def locate_funq(): - """find the funq executable""" - return tools.which('funq') - - -class FunqPlugin(Plugin): - - """ - Nosetests plugin to integrate funq. - """ - name = 'funq' - - _instance = None - - @classmethod - def instance(cls): - return cls._instance - - def options(self, parser, env=None): - env = env or os.environ - super(FunqPlugin, self).options(parser, env=env) - parser.add_option('--funq-conf', - dest='funq_conf', - default=env.get('NOSE_FUNQ_CONF') or 'funq.conf', - help="funq configuration file, defaults to" - " `funq.conf` [NOSE_FUNQ_CONF].") - parser.add_option('--funq-gkit', - dest='funq_gkit', - default=env.get('NOSE_FUNQ_GKIT') or 'default', - help="Choose a specific graphic toolkit. This allows" - " to define default different aliases" - " Default: `default` [NOSE_FUNQ_GKIT]`") - gkit_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'aliases-gkits.conf') - parser.add_option('--funq-gkit-file', - dest='funq_gkit_file', - default=env.get('NOSE_FUNQ_GKIT_FILE') or gkit_file, - help="Override the file that defines graphic" - " toolkits. Default: `%s` [NOSE_FUNQ_GKIT_FILE]" - % gkit_file) - parser.add_option('--funq-attach-exe', - dest='funq_attach_exe', - default=env.get('NOSE_FUNQ_ATTACH_EXE') - or locate_funq(), - help="Complete path to the funq executable." - " [NOSE_FUNQ_ATTACH_EXE]") - parser.add_option('--funq-trace-tests', - dest='funq_trace_tests', - default=env.get('NOSE_FUNQ_TRACE_TESTS'), - help="A file in which start and end of tests will be" - " logged. [NOSE_FUNQ_TRACE_TESTS]") - parser.add_option('--funq-trace-tests-encoding', - dest='funq_trace_tests_encoding', - default=env.get('NOSE_FUNQ_TRACE_TESTS_ENCODING') - or 'utf-8', - help="encoding of the file used in" - " --funq-trace-tests." - " [NOSE_FUNQ_TRACE_TESTS_ENCODING]") - parser.add_option('--funq-screenshot-folder', - dest="funq_screenshot_folder", - default=env.get("NOSE_FUNQ_SCREENSHOT_FOLDER") - or os.path.realpath("screenshot-errors"), - help="Folder to saves screenshots on error." - " Default: screenshot-errors." - " [NOSE_FUNQ_SCREENSHOT_FOLDER]") - parser.add_option('--funq-snooze-factor', - dest="funq_snooze_factor", - default=env.get("NOSE_FUNQ_SNOOZE_FACTOR") - or 1.0, - help="Allow to specify a factor on every timeout." - " Default: 1.0. [NOSE_FUNQ_SNOOZE_FACTOR]") - - def configure(self, options, cfg): - Plugin.configure(self, options, cfg) - if not self.enabled: - return - conf_file = options.funq_conf = os.path.realpath(options.funq_conf) - if not os.path.isfile(conf_file): - raise Exception( - "Missing configuration file of funq: `%s`" % conf_file) - conf = ConfigParser() - conf.read([conf_file]) - self.app_registry = ApplicationRegistry() - self.app_registry.register_from_conf(conf, options) - register_funq_app_registry(self.app_registry) - self.trace_tests = options.funq_trace_tests - self.trace_tests_encoding = \ - options.funq_trace_tests_encoding - self.screenshoter = ScreenShoter(options.funq_screenshot_folder) - tools.SNOOZE_FACTOR = float(options.funq_snooze_factor) - FunqPlugin._instance = self - - def beforeTest(self, test): - message = "Starting test `%s`" % test.id() - lines = message_with_sep(message) - for line in lines: - LOG.info(line) - if self.trace_tests: - with codecs.open(self.trace_tests, 'a', - self.trace_tests_encoding) as f: - f.write('\n'.join(lines)) - f.write('\n') - - def afterTest(self, test): - message = "Ending test `%s`" % test.id() - lines = message_with_sep(message) - for line in lines: - LOG.info(line) - if self.trace_tests: - with codecs.open(self.trace_tests, 'a', - self.trace_tests_encoding) as f: - f.write('\n'.join(lines)) - f.write('\n') - - def describeTest(self, test): - return u'%s' % test.id() - - def take_screenshot(self, test): - if isinstance(test, MultiFunqTestCase): - if test.__app_config__: - for k, v in test.__app_config__.items(): - if v.screenshot_on_error: - self.screenshoter.take_screenshot( - test.funq[k], - '%s [%s]' % (test.id(), k) - ) - elif isinstance(test, FunqTestCase): - if test.__app_config__: - if test.__app_config__.screenshot_on_error: - self.screenshoter.take_screenshot(test.funq, test.id()) - - def prepareTestResult(self, result): - _addError = result.addError - _addFailure = result.addFailure - - def addError(test, err): - self.take_screenshot(test.test) - _addError(test, err) - - def addFailure(test, err): - self.take_screenshot(test.test) - _addFailure(test, err) - result.addError = addError - result.addFailure = addFailure diff --git a/client/funq/tests/test_models.py b/client/funq/tests/test_models.py index 35d7ae7..54ed655 100644 --- a/client/funq/tests/test_models.py +++ b/client/funq/tests/test_models.py @@ -32,6 +32,7 @@ # The fact that you are presently reading this means that you have had # knowledge of the CeCILL v2.1 license and that you accept its terms. +import pytest from funq import models @@ -65,6 +66,7 @@ class MyWidget(models.Widget): class TestModelItems: + @pytest.fixture(autouse=True) def setup(self): data = { 'items': [ diff --git a/client/funq/tests/test_screenshoter.py b/client/funq/tests/test_screenshoter.py index 9396d6b..a4a118f 100644 --- a/client/funq/tests/test_screenshoter.py +++ b/client/funq/tests/test_screenshoter.py @@ -32,7 +32,6 @@ # The fact that you are presently reading this means that you have had # knowledge of the CeCILL v2.1 license and that you accept its terms. -from nose.tools import assert_equals, assert_true from funq import screenshoter import tempfile import shutil diff --git a/client/funq/tests/test_tools.py b/client/funq/tests/test_tools.py index ab15123..6992801 100644 --- a/client/funq/tests/test_tools.py +++ b/client/funq/tests/test_tools.py @@ -32,7 +32,7 @@ # The fact that you are presently reading this means that you have had # knowledge of the CeCILL v2.1 license and that you accept its terms. -from nose.tools import assert_equals, assert_true, raises +import pytest from funq import tools import time import sys @@ -45,18 +45,18 @@ def func(): assert tools.wait_for(func, 0.0) -@raises(tools.TimeOutError) def test_wait_for_timeout(): def func(): return False - tools.wait_for(func, 0.0) + with pytest.raises(tools.TimeOutError): + tools.wait_for(func, 0.0) -@raises(Exception) def test_wait_for_custom_exc(): def func(): return Exception() - tools.wait_for(func, 0.0) + with pytest.raises(Exception): + tools.wait_for(func, 0.0) def test_wait_for_some_time(): diff --git a/doc-dev/general.rst b/doc-dev/general.rst index 33aec38..7091c29 100644 --- a/doc-dev/general.rst +++ b/doc-dev/general.rst @@ -47,7 +47,7 @@ Choix d'implémentation - partie client Le client est implémenté en Python - et c'est ainsi que les tests doivent être écrits. -Pour lancer les tests, la librairie **nosetests** est utilisée - c'est une +Pour lancer les tests, la librairie **pytest** est utilisée - c'est une dépendance du client. Tests unitaires @@ -83,7 +83,7 @@ Pour la partie client: .. code-block:: bash cd client - nosetests + pytest .. note:: @@ -92,13 +92,11 @@ Pour la partie client: .. code-block:: bash cd client - nosetests --with-coverage --cover-package funq + pytest --with-coverage --cover-package funq -La partie client requiert le framework Python **nose** [1] pour lancer les tests, -et **coverage.py** [2] pour la couverture. +La partie client requiert le framework Python **pytest** [1] pour lancer les tests. -* [1] https://nose.readthedocs.org/en/latest/ -* [2] http://nedbatchelder.com/code/coverage/ +* [1] https://pytest.readthedocs.org/en/latest/ Documentation ------------- diff --git a/tests-functionnal/setup.cfg b/tests-functionnal/setup.cfg index 2cc16aa..f111a55 100644 --- a/tests-functionnal/setup.cfg +++ b/tests-functionnal/setup.cfg @@ -1,3 +1,3 @@ -[nosetests] +[pytest] verbosity=2 with-funq=1