Eduardo Olivares 5af7c53c05 Add support to skip tests from CLI
With this patch, a new pytest optional arg has been added:
--skipregex

When it is used, tests are skipped when the regex is found in their test
names. Fully qualified test names are used for this search. Example:
tobiko.tests.unit.test_exception.TestException.test_init

It can be used from CLI with pytest like this:
$ .tox/py3/bin/pytest \
  --skipregex='test_join_chunks_.*_bytes|test_join_chunks_with_unicodes' \
  tobiko/tests/unit

It can be used from CLI with tox like this:
$ PYTEST_ADDOPTS="--skipregex='test_join_chunks_.*_bytes|test_join_chunks_with_unicodes'" \
  TOX_PYTHON=python3.9 \
  tox -e py3

It can be used from the Tobiko Infrared plugin by using the following
option (limitation: the skipregex is applied to all the steps from the
the executed Tobiko workflow):
$ infrared tobiko ... --pytest-addopts "--skipregex='test_join_chunks_.*_bytes|test_join_chunks_with_unicodes'"

It can be used from a zuul job by configuring the following variable
within the zuul job yaml file (limitation: the skipregex is applied to
all the steps from the executed Tobiko workflow):
pytest_addopts_global: "--skipregex='test_join_chunks_.*_bytes|test_join_chunks_with_unicodes'"

Change-Id: I8ee32ba467bd70142816953598d1736fa353d3d0
2023-12-04 12:17:26 +01:00

83 lines
2.0 KiB
YAML

---
- name: set Tox command line fact
set_fact:
tox_command_line: >
{{ tox_command }}
{% if tox_envlist %} -e {{ tox_envlist | quote }} {% endif %}
{{ tox_extra_args }}
- name: normalize white spaces from Tox command line
set_fact:
tox_command_line: '{{ tox_command_line.split() | join(" ") }}'
- name: initialize tox_env to empty dict for each test suite execution
set_fact:
tox_env: {}
- name: combine and normalize environment variable values
set_fact:
tox_env: >
{{ tox_env |
combine({ item.key: (item.value | string).strip() }) }}
loop: >
{{ ((tox_environment | from_yaml | dict2items) +
(tox_constrain_env | dict2items)) }}
when:
- (item.value | string).strip() # skip empty strings
- name: show tox variables
debug: var="{{ item }}"
loop:
- tox_command_line
- tox_description
- tox_dir
- tox_env
- tox_expected_rcs
- name: "{{ tox_description }}"
command:
chdir: '{{ tox_dir }}'
cmd: '{{ tox_command_line }}'
register:
run_tox
environment: '{{ tox_env }}'
failed_when: run_tox.rc != tox_succeeded_rc
ignore_errors: yes
- name: reset values used to generate tox_constrain_env after executing a test suite
set_fact:
pytest_addopts: '{{ pytest_addopts_global }}'
test_flaky: false
pytest_markers: "{% if not test_flaky%}not flaky{% endif %}"
pytest_maxfail: ''
tox_constraints: ''
tox_run_tests_timeout: 18000
- name: "show test cases errors"
debug: var=run_tox.stderr_lines
when:
- run_tox is failed
- (run_tox.stderr_lines | length) > 0
- name: 'raise test cases failure'
debug:
msg: 'test cases have failed'
when: run_tox is failed
failed_when:
- not (ignore_test_failures | bool)
- run_tox.rc not in tox_expected_rcs
- name: 'raise error in case of timeout'
debug:
msg: 'timeout during the execution of the tests'
when: run_tox is failed
failed_when:
- (run_tox.stdout_lines | length) > 0
- run_tox.stdout | regex_search('ERROR.*run_tests.py timeout out after')