Coverage for gws-app/gws/test/__init__.py: 100%
0 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""GWS Test Framework
3To run tests in GWS, you need to start a docker-compose environment with the GWS container and some auxiliary containers, and run the test script in the GWS container.
5All test functionality is invoked via ``make.sh test`` commands.
7There are two ways to run the tests:
9- automatically, with ``make.sh test go``. This configures the docker-compose environment for testing, runs tests, and shuts down.
10- manually, where you first start the environment with ``make.sh test start`` and then invoke tests with ``make.sh test run``.
12In the latter case, it's convenient to start the compose environment in the foreground and invoke ``test run`` in another shell.
14When testing manually, you can also select specific tests with the ``--only`` option and provide additional pytest options. See ``make.sh test -h`` for details.
16User/group
17----------
19On Linux systems, the user running the tests (you) must be able to run ``docker``. Use ``sudo usermod -aG docker $USER`` to add yourself to the ``docker`` group.
20See https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
22By default, test containers use your uid/gid to run processes (like the postgres server), you can override this with ``runner.uid`` and ``runner.gid`` options.
25Configuration
26-------------
28On your machine, you need a dedicated directory where the tester stores its stuff ("base_dir").
30The configuration is in the file "test.ini" in the application root directory. If you need custom options (e.g., a custom base directory path), create a secondary "ini" file with your overrides and pass it as ``make.sh test --ini myconfig.ini``.
32Writing tests
33-------------
35All test files must end with ``_test.py``. All test functions must start with ``test_``. It is recommended to always import the test utilities library, which provides some useful shortcuts and mocks. Here is an example of a test file::
37 '''Testing the foo package.'''
39 import gws
40 import gws.lib.foo as foo
41 import gws.test.util as u
43 def test_one():
44 assert foo.bar == 1
46 def test_two():
47 with u.raises(ValueError):
48 foo.blah()
50Coverage reports
51----------------
53Pass the ``--coverage`` option to ``test run`` to create a coverage report. It will be created in ``base_dir/coverage``.
54With ``test go``, the coverage report is created automatically.
56"""