Skip to content

Commit 2e705a8

Browse files
author
Oleg Averkin
committed
Phase6 PyTest Parallel Execution
Add pytest-xdist library Add pytest-rerunfailures library Add random test for check re-run
1 parent 21e5c04 commit 2e705a8

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

.circleci/config.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,20 @@ jobs:
66
working_directory: ~/repo
77
steps:
88
- checkout
9-
- restore_cache:
10-
keys:
11-
- v1-dependencies-{{ checksum "requirements.txt" }}
12-
- v1-dependencies-
139
- run:
1410
name: install dependencies
1511
command: |
16-
python3 -m venv venv
17-
. venv/bin/activate
18-
pip install -r requirements.txt
19-
wget https://dl.bintray.com/qameta/maven/io/qameta/allure/allure-commandline/2.11.0/allure-commandline-2.11.0.zip
20-
unzip allure-commandline-2.11.0.zip
21-
- save_cache:
22-
paths:
23-
- ./venv
24-
key: v1-dependencies-{{ checksum "requirements.txt" }}
12+
sudo pip install -r requirements.txt
13+
sudo npm install -g allure-commandline --save-dev
2514
- run:
2615
name: run tests
2716
command: |
28-
. venv/bin/activate
29-
chmod -R 777 ./allure-2.11.0/bin/
30-
pytest --alluredir=./allure-results tests/test_jira_api.py
17+
pytest -n 3 --dist=loadscope -v --reruns 2 --alluredir ./allure-results tests/test_jira_api.py
3118
- run:
3219
name: run report
3320
when: always
3421
command: |
35-
./allure-2.11.0/bin/allure generate -c
22+
allure generate -c
3623
- store_artifacts:
3724
path: allure-report
3825
destination: allure-report

requirements.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
allure-pytest==2.6.2
2-
allure-python-commons==2.6.2
1+
allure-pytest==2.5.1
2+
allure-python-commons==2.5.1
3+
apipkg==1.5
34
appdirs==1.4.0
45
astroid==1.4.9
56
atomicwrites==1.3.0
@@ -11,6 +12,7 @@ coverage==4.3.4
1112
coveralls==1.1
1213
crayons==0.2.0
1314
docopt==0.6.2
15+
execnet==1.6.0
1416
fibonacci==1.0.0
1517
isort==4.2.5
1618
lazy-object-proxy==1.2.2
@@ -22,12 +24,16 @@ packaging==16.8
2224
pluggy==0.9.0
2325
py==1.8.0
2426
pyparsing==2.1.10
25-
pytest==4.4.0
27+
pytest==3.7.2
2628
pytest-base-url==1.4.1
27-
pytest-html==1.20.0
28-
pytest-metadata==1.8.0
29-
pytest-selenium==1.16.0
29+
pytest-forked==0.2
30+
pytest-html==1.19.0
31+
pytest-metadata==1.7.0
32+
pytest-parallel==0.0.2
33+
pytest-rerunfailures==4.1
34+
pytest-selenium==1.14.0
3035
pytest-variables==1.7.1
36+
pytest-xdist==1.23.0
3137
requests==2.13.0
3238
restflow==0.8b0
3339
selenium==3.141.0
@@ -36,4 +42,3 @@ urllib3==1.24.2
3642
webdriver-manager==1.7
3743
wrapt==1.10.8
3844
xmltodict==0.12.0
39-
pytest==4.4.0

src/jira_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
created_issues = []
1919
j = JSONFixture()
20+
times_rerun = []
2021

2122

2223
class JiraApi:
@@ -60,3 +61,11 @@ def delete_all_issues(self):
6061
result = JiraApi.delete_issue(self, issue_id)
6162
response_codes_list.append(result.status_code)
6263
return response_codes_list
64+
65+
@allure.step
66+
def rerun(self):
67+
if len(times_rerun) == 0:
68+
times_rerun.append(1)
69+
return 1
70+
else:
71+
return 2

tests/test_jira_api.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_login_to_jira(self, response, expected):
2222
def test_post_issue(self):
2323
response = api.post_issue("OA API Issue001", "OlegAverkin", "Low")
2424
assert response.status_code == 201
25+
assert "WEBINAR" in response.json().get('key')
2526

2627
@allure.tag('api')
2728
@allure.title("Update issue")
@@ -31,17 +32,7 @@ def test_update_issue(self):
3132
issue_id = response.json().get('id')
3233
response_update = api.update_issue(issue_id, "OA API Issue002 Updated", "OlegAverkin", "Low")
3334
assert response_update.status_code == 204
34-
35-
@allure.tag('api')
36-
@allure.title("Post multiple issues")
37-
@pytest.mark.api
38-
@pytest.mark.parametrize("response,expected", [
39-
(api.post_issue("OA API Issue003", "OlegAverkin", "Low"), 201),
40-
(api.post_issue("OA API Issue004", "OlegAverkin", "Low"), 201),
41-
(api.post_issue("OA API Issue005", "OlegAverkin", "Low"), 201),
42-
(api.post_issue("OA API Issue006", "OlegAverkin", "Low"), 201)])
43-
def test_post_issues(self, response, expected):
44-
assert response.status_code == expected
35+
api.delete_all_issues()
4536

4637
@allure.tag('api')
4738
@allure.title("Missing required fields")
@@ -63,17 +54,17 @@ def test_post_issue_long_summary(self):
6354
@allure.title("Test search issue")
6455
@pytest.mark.api
6556
def test_search_1_issue(self):
66-
response = api.search_issue("Issue001")
57+
response = api.search_issue("OAsearch1")
6758
assert response.status_code == 200
6859
assert response.json().get('total') == 1
6960

7061
@allure.tag('api')
7162
@allure.title("Test five issue")
7263
@pytest.mark.api
7364
def test_search_5_issues(self):
74-
response = api.search_issue("OA")
65+
response = api.search_issue("OAsearch5")
7566
assert response.status_code == 200
76-
assert response.json().get('total') == 6
67+
assert response.json().get('total') == 5
7768

7869
@allure.tag('api')
7970
@allure.title("Test search unknown issue")
@@ -84,8 +75,7 @@ def test_search_none_issue(self):
8475
assert response.json().get('total') == 0
8576

8677
@allure.tag('api')
87-
@allure.title("Delete all issues")
78+
@allure.title("Random test for re-run")
8879
@pytest.mark.api
89-
def test_delete_all_issues(self):
90-
response = api.delete_all_issues()
91-
assert len(response) == 6
80+
def test_random(self):
81+
assert api.rerun() == 2

0 commit comments

Comments
 (0)