Skip to content

Commit

Permalink
docs explaing pytest for Python and C++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
yoctoyotta1024 committed Feb 28, 2024
1 parent f2b8d48 commit a6465e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Contents

usage/getstart
usage/ourdocs
usage/ourtests
src_py/index
src_cxx/index

Expand Down
36 changes: 36 additions & 0 deletions docs/source/usage/ourtests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Our Tests
=========

This project uses pytest for executing the Python tests in the `./tests` directory. These tests are
included in the CI.yml and can be used to test both Python and C++ code.

.. _python-test:

Testing Python Code
###################

Easily done with pytest!

Simply import the code you want to test (e.g. module, function, class etc.)
within a script called ``./tests/test_[name].py`` with a "name" of your choosing in the `./tests`
directory.

Then run pytest on the entire tests directory or on your test. For example, ``pytest ./tests`` would test
every test in the `./tests` directory, whereas ``pytest test_[name].py`` runs just your test.

Testing C++ Code
################

For testing C++ code, we first make a Python module out of it using pybind11, e.g. via

.. code-block:: console
$ cmake -S ./ -B ./build
$ cd build && make
which fetches and uses pybind11 (see CMakeLists.txt) to make a Python module out of the C++ code -
provided you have first written appropriate bindings(!). The Python module is then tested using
pytest just :ref:`like an ordinary python module <python-test>`.

You can find out more about pybind11 by visiting
`their repository <https://github.com/pybind/pybind11/>`_

0 comments on commit a6465e9

Please sign in to comment.