diff --git a/README.md b/README.md index e9e8d08..27490f3 100755 --- a/README.md +++ b/README.md @@ -67,17 +67,15 @@ in turn imports `ioc/config.cmd` to get the current configuration. ## Running the tests -TODO: Add doc for --stresstest and --log flags and mention -s flag - ### General Running tests requires the following three steps: -- Starting the IOC via `ioc/startioc` (see [Configuration](#starting-the-ioc)) - Creating (if not done previously) and activating a suitable virtual environment: ```bash ./maketestenv source testenv/bin/activate ``` +- Starting the IOC via `ioc/startioc` (see [Configuration](#starting-the-ioc)) - Running the desired test(s) via pytest. For example: ```bash pytest tests/turboPmac1/ @@ -89,6 +87,11 @@ To run a specific test file: pytest tests/turboPmac1/ax1/test_common.py ``` +### Configuring pytest + + +TODO: Add doc for --stresstest and --log flags and mention -s flag + And to run a specific test "test_something" within this file: ```bash pytest tests/turboPmac1/ax1/test_common.py -k 'test_something' @@ -97,7 +100,41 @@ pytest tests/turboPmac1/ax1/test_common.py -k 'test_something' Pytest normally suppresses stdout (which is where Pythons `print` writes by default). To show it, use the `-s` flag: ```bash -pytest -s tests/turboPmac1/ax1/test_common.py -k 'test_something' +pytest -s tests/turboPmac1/ax1/test_common.py +``` + +Two custom flags exist in this test framework: `--stresstest ` and `--log`: + +#### --stresstest + +Adding this flags enables some stress tests, which are essentially loops over +"normal" tests. In the source code, they are marked with +`@pytest.mark.stresstest`. Since these tests greatly increase the total runtime, +it is recommended to only run them after the "normal" tests pass. +```bash +pytest --stresstest tests/turboPmac1/ax1/test_common.py +``` + +#### --log + +Each motor has its own dedicated logger, whose loglevel can be set with the flag +`--log=LEVEL`. `LEVEL` should be one of the `logging` - native levels - i.e. +`DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` (see +https://docs.python.org/3/library/logging.html#logging-levels). To see the level +description, run: +```bash +pytest --help | grep -- '--log=' +``` + +To specify the log level for a test run: +```bash +pytest --log=INFO tests/turboPmac1/ax1/test_common.py +``` + +To see the log in stdout: + +```bash +pytest --log=INFO -s tests/turboPmac1/ax1/test_common.py ``` ### Parallelizing tests over motors diff --git a/tests/conftest.py b/tests/conftest.py index ebd0e63..95f7f3a 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ from pathlib import Path import logging +import textwrap from caproto.sync.client import read import pytest @@ -47,7 +48,7 @@ def pytest_addoption(parser): "--log", action="store", default="ERROR", - help=""" + help=textwrap.dedent(""" Set log level: - DEBUG: Show all raw caput and caget commands - INFO: Write high-level commands (e.g. move, stop, home etc.) @@ -56,7 +57,7 @@ def pytest_addoption(parser): - CRITICAL: Not used All error levels higher than the defined one are forwarded to the Pytest logger. - """ + """) )