Skip to content

Commit

Permalink
[pytest] introduce pytest_runner playbook
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak <stepanb@mellanox.com>
  • Loading branch information
Stepan Blyschak committed Aug 1, 2019
1 parent b34493a commit 78b2907
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions ansible/roles/test/tasks/pytest_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
- name: print a warning
debug:
msg:
- "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
- "!!!!!! Ansible playbook for running {{ testcase_name }} is now deprecated !!!!!!"
- "!!!!!! This playbook is just a wrapper to run py.test in sonic-mgmt/tests !!!!!!"
- "!!!!!!!!!!!!!!!!!!!!!!!!!! Consider using py.test !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
- "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"

- fail:
msg: Test node is not defined
when: test_node is not defined

- fail:
msg: Testbed is not defined
when: testbed_name is not defined

- name: set py.test command variable
set_fact:
pytest_cmd: 'py.test {{ test_node }}'

- name: append filter expression if needed
set_fact:
pytest_cmd: '{{ pytest_cmd }} -k "{{ test_filter }}"'
when: test_filter is defined

- name: append mark if needed
set_fact:
pytest_cmd: '{{ pytest_cmd }} -m {{ test_mark }}'
when: test_mark is defined

- name: append testbed name
set_fact:
pytest_cmd: '{{ pytest_cmd }} --testbed={{ testbed_name }}'

# We could use ansible_inventory_sources magic variable but it is available in ansible >=2.5
- name: append inventory file
set_fact:
pytest_cmd: '{{ pytest_cmd }} --inventory=../ansible/inventory'

- name: append testbed file
set_fact:
pytest_cmd: '{{ pytest_cmd }} --testbed_file=../ansible/testbed.csv'

- name: append host pattern
set_fact:
pytest_cmd: '{{ pytest_cmd }} --host-pattern={{ testbed_name }}'

- name: append verbosity flag
set_fact:
pytest_cmd: '{{ pytest_cmd }} -v'

- debug: var=pytest_cmd

- name: run py.test
connection: local
shell: '{{ pytest_cmd }}'
args:
chdir: ../tests/
environment:
ANSIBLE_LIBRARY: ../ansible/library/
register: out

- debug: msg='{{ out.stdout_lines }}'

0 comments on commit 78b2907

Please sign in to comment.