-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytest_run.yml
78 lines (68 loc) · 2.15 KB
/
pytest_run.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
- name: Run Pytest
hosts: tester
gather_facts: yes
any_errors_fatal: true
vars:
repo_folder: 'pytest-repo/'
output_prefix: '{{ item }}-{{ ansible_date_time.epoch }}.xml'
tasks:
- name: install python-pip
shell: |
curl https://bootstrap.pypa.io/get-pip.py | python
when: ansible_python_version is version('3', '<')
become: true
- name: install python3-pip
package:
name: python3-pip
state: present
when: ansible_python_version is version('3', '>=')
become: true
- name: install python virtualenv
pip:
name: virtualenv
state: present
become: true
- name: install pytest via pip
pip:
name: pytest
state: present
virtualenv: /tmp/pytest_venv
- name: Install packages
become: true
package:
name:
- git
state: latest
- name: Clean old folder
file:
path: "{{ repo_folder }}"
state: absent
- name: Cloning git repo
shell: |
export GIT_SSL_NO_VERIFY=true
git clone {{ test.repo }} {{ repo_folder }}
tags: skip_ansible_lint
- name: check for requirements.txt file
stat:
path: "{{ repo_folder }}requirements.txt"
register: stat_result
- name: install requirements.txt file
pip:
requirements: "requirements.txt"
virtualenv: /tmp/pytest_venv
chdir: "{{ repo_folder }}"
when: stat_result.stat.exists == True
- name: Execute test
ignore_errors: true
shell: source /tmp/pytest_venv/bin/activate && pytest -v {{ repo_folder }}{{ item }}
--junitxml={{ output_prefix }} 2>&1 --tb=no -r fp || true
when: test.run|default(False)
loop: "{{ test.file }}"
register: pytest_execution
- name: Fetch JUnit XML results file
fetch:
src: "{{ output_prefix }}"
dest: "{{ inventory_dir }}/pytest_results/{{ output_prefix }}"
flat: yes
fail_on_missing: yes
loop: "{{ test.file }}"