zephyr/scripts/tests/twister
Anas Nashif ac4aabc10d twister: support filtering tests using regex
Use --test-pattern to filter scenarios using regular expressions, for
example:

./scripts/twister --test-pattern '^kernel.semaphore.*' -v

will run all those test using this identifier pattern, and nothing else.
Multiple patterns are possible.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-07-21 07:23:58 -04:00
..
pytest_integration
test_data
conftest.py twister: make no-detailed-test-id default 2025-07-19 15:50:47 -04:00
README.md
test_cmakecache.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_config_parser.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_environment.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_errors.py
test_handlers.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_hardwaremap.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_harness.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_jobserver.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_log_helper.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_mixins.py
test_platform.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_quarantine.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_runner.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_scl.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_testinstance.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_testplan.py twister: support filtering tests using regex 2025-07-21 07:23:58 -04:00
test_testsuite.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00
test_twister.py scripts: requirements: remove dependency to mock package 2025-07-19 15:42:19 -04:00

Twister Testing

Running the tests require the environment variable ZEPHYR_BASE to be set.

Twister Testsuite are located in $ZEPHYR_BASE/scripts/tests directory with all the data files in $ZEPHYR_BASE/scripts/test_data directory.

Dependencies

Install all the dependencies using

pip install -r $ZEPHYR_BASE/scripts/requirements-build-test.txt

Executing testsuite

The testcases can be executed from the root directory using

pytest $ZEPHYR_BASE/scripts/tests/twister

Twister Coverage

The coverage for all the tests can be run using the command below. This will collect all the tests available.

coverage run -m pytest $ZEPHYR_BASE/scripts/tests/twister/

Then we can generate the coverage report for just twister script using

coverage report -m $ZEPHYR_BASE/scripts/pylib/twister/

To generate the coverage report for twister script use below command

coverage report -m $ZEPHYR_BASE/scripts/twister

The html coverage report for twister can be generated using

coverage html twister

If needed,the full coverage html report can be generated in every run of "pytest" in the tests directory using configuration file (setup.cfg).

Organization of tests

  • conftest.py: Contains common fixtures for use in testing the twister tool.
  • test_twister.py : Contains basic testcases for environment variables, verifying testcase & platform schema's.
  • test_testsuite_class.py : Contains testcases for Testsuite class (except reporting functionality) in twisterlib.py.
  • test_testinstance.py : Contains testcases for Testinstance and Testcase class.
  • test_reporting_testsuite.py : Contains testcases for reporting functionality of Testsuite class of twister.