Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating from nosetests to pytest #83

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ jobs:
py: "3.8"
container: "ubuntu:20.04"
packages: "qt5-default qttools5-dev-tools qtdeclarative5-dev qml-module-qtquick2"
nosetests: 1
- qt: 5 # 5.15
py: "3.10"
container: "ubuntu:22.04"
packages: "qtbase5-dev qttools5-dev-tools qtdeclarative5-dev qml-module-qtquick2"
nosetests: 0 # Nosetest not working anymore
- qt: 6 # 6.2
py: "3.10"
container: "ubuntu:22.04"
packages: "qt6-base-dev qt6-tools-dev qt6-tools-dev-tools qt6-declarative-dev libqt6opengl6-dev qml6-module-*"
nosetests: 0 # Nosetest not working anymore
- qt: 6 # 6.4
py: "3.12"
container: "ubuntu:24.04"
packages: "qt6-base-dev qt6-tools-dev qt6-tools-dev-tools qt6-declarative-dev libqt6opengl6-dev qml6-module-*"
nosetests: 0 # Nosetest not working anymore
env:
DEBIAN_FRONTEND: noninteractive
FUNQ_QT_MAJOR_VERSION: "${{ matrix.qt }}"
Expand All @@ -46,6 +42,10 @@ jobs:
python3 python3-pip python3-flake8 \
${{ matrix.packages }}

- name: Install Python requirements
run: |
pip install wheel pytest pytest-runner

# Stylecheck
- name: Flake8
run: python3 -m flake8 client/funq server/funq_server
Expand All @@ -64,33 +64,30 @@ jobs:

# Server
- name: Install server
run: cd server && python3 setup.py develop
run: cd server && python -m pip install --editable .

# Client
- name: Install client
run: cd client && python3 setup.py develop
run: cd client && python -m pip install --editable .
- name: Test client
run: cd client && python3 setup.py test
if: ${{ matrix.nosetests != 0 }}
run: cd client && pytest -v tests

# Functional tests
- name: Build test app
run: cd tests-functionnal/funq-test-app && cmake . && make
- name: Test injection
run: xvfb-run -a funq tests-functionnal/funq-test-app/funq-test-app --exit-after-startup
- name: Test functional
run: cd tests-functionnal && xvfb-run -a nosetests
if: ${{ matrix.nosetests != 0}}
run: cd tests-functionnal && xvfb-run -a pytest -v

macos:
name: "qt:${{ matrix.qt }} on ${{ matrix.runner }}"
runs-on: "${{ matrix.runner }}"
strategy:
matrix:
include:
# Note: Nosetest doesn't work anymore with recent Python versions!
- {qt: "5", runner: "macos-12", nosetests: 0}
- {qt: "6", runner: "macos-14", nosetests: 0}
- {qt: "5", runner: "macos-12"}
- {qt: "6", runner: "macos-14"}
env:
FUNQ_QT_MAJOR_VERSION: "${{ matrix.qt }}"
PIP_BREAK_SYSTEM_PACKAGES: 1
Expand All @@ -101,7 +98,8 @@ jobs:
brew install cmake qt@${{ matrix.qt }}
brew link --force qt@${{ matrix.qt }}
echo "$(brew --prefix qt${{ matrix.qt }})/bin" >> $GITHUB_PATH
pip3 install setuptools flake8
pip3 install setuptools flake8 wheel pytest pytest-runner


# Stylecheck
- name: Flake8
Expand All @@ -121,23 +119,21 @@ jobs:

# Server
- name: Install server
run: cd server && python3 setup.py develop
run: cd server && python -m pip install --editable .

# Client
- name: Install client
run: cd client && python3 setup.py develop
run: cd client && python -m pip install --editable .
- name: Test client
run: cd client && python3 setup.py test
if: ${{ matrix.nosetests != 0 }}
run: cd client && pytest -v tests

# Functional tests
- name: Build test app
run: cd tests-functionnal/funq-test-app && cmake . && make
- name: Test injection
run: funq tests-functionnal/funq-test-app/funq-test-app --exit-after-startup
- name: Test functional
run: cd tests-functionnal && xvfb-run -a nosetests
if: ${{ matrix.nosetests != 0}}
run: cd tests-functionnal && xvfb-run -a pytest -v

windows:
name: "qt:${{ matrix.qt }} py:${{ matrix.py }} ${{ matrix.arch }} on windows"
Expand All @@ -152,23 +148,20 @@ jobs:
qt_arch: "win32_mingw81"
qt_tools: "tools_mingw,qt.tools.win32_mingw810"
compiler_path: "D:/a/funq/Qt/Tools/mingw810_32/bin"
nosetests: 1
- py: "3.8"
arch: "x64"
qt: 6
qt_full: "6.7.0"
qt_arch: "win64_mingw"
qt_tools: "tools_mingw1310"
compiler_path: "D:/a/funq/Qt/Tools/mingw1310_64/bin"
nosetests: 1
- py: "3.11"
arch: "x64"
qt: 6
qt_full: "6.7.0"
qt_arch: "win64_mingw"
qt_tools: "tools_mingw1310"
compiler_path: "D:/a/funq/Qt/Tools/mingw1310_64/bin"
nosetests: 0 # Nosetest not working anymore
env:
CMAKE_GENERATOR: "MinGW Makefiles"
CC: "${{ matrix.compiler_path }}/gcc.exe"
Expand Down Expand Up @@ -206,20 +199,20 @@ jobs:

# Server
- name: Install server
run: cd server && python3 setup.py develop
run: cd server && python -m pip install --editable .

# Client
- name: Install test requirements
run: pip install wheel pytest pytest-runner
- name: Install client
run: cd client && python3 setup.py develop
run: cd client && python -m pip install --editable .
- name: Test client
run: cd client && python3 setup.py test
if: ${{ matrix.nosetests != 0 }}
run: cd client && pytest -v tests

# Functional tests
- name: Build test app
run: cd tests-functionnal/funq-test-app && cmake . && make
- name: Test injection
run: funq tests-functionnal/funq-test-app/funq-test-app.exe --exit-after-startup
- name: Test functional
run: cd tests-functionnal && nosetests
if: ${{ matrix.nosetests != 0}}
run: cd tests-functionnal && pytest -v
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 !
4 changes: 2 additions & 2 deletions client/doc/gkit_aliases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 16 additions & 32 deletions client/doc/launching_tests.rst
Original file line number Diff line number Diff line change
@@ -1,90 +1,74 @@
Launching tests (nose)
======================

Tests are launched by `nose <https://nose.readthedocs.org/en/latest/>`_,
Tests are launched by `pytest <https://pytest.readthedocs.org/en/latest/>`_,
and you have to tell it to use the **funq** plugin.

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 <http://nose.readthedocs.org/en/latest/plugins/writing.html>`_.
It is also easy to write your own `pytest plugins <https://docs.pytest.org/en/latest/how-to/writing_plugins.html#writing-your-own-plugin>`_.
2 changes: 1 addition & 1 deletion client/doc/qml_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Run the test

Just run::

nosetests --with-funq
pytest --with-funq

In the `qmltest` folder and watch it pass.

Expand Down
16 changes: 8 additions & 8 deletions client/doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ And that funq is installed with:

.. code-block:: bash

nosetests -h | grep 'with-funq'
pytest -h | grep 'with-funq'

.. important::

Expand Down Expand Up @@ -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::
Expand All @@ -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.
Expand Down Expand Up @@ -159,7 +159,7 @@ Now you can start tests again:

.. code-block:: bash

nosetests --with-funq
pytest --with-funq

.. note::

Expand All @@ -170,15 +170,15 @@ Now you can start tests again:

.. code-block:: bash

nosetests --with-funq test_widgets.py
pytest --with-funq test_widgets.py

.. important::

It is really important even for functional tests to not write tests
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
-------------
Expand Down
Loading
Loading