Skip to content

Commit

Permalink
Phase6 PyTest Parallel Execution
Browse files Browse the repository at this point in the history
Add pytest-xdist library
Add pytest-rerunfailures library
Add random test for check re-run
  • Loading branch information
Oleg Averkin committed May 28, 2019
1 parent 21e5c04 commit 2e705a8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
21 changes: 4 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,20 @@ jobs:
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
- v1-dependencies-
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
wget https://dl.bintray.com/qameta/maven/io/qameta/allure/allure-commandline/2.11.0/allure-commandline-2.11.0.zip
unzip allure-commandline-2.11.0.zip
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
sudo pip install -r requirements.txt
sudo npm install -g allure-commandline --save-dev
- run:
name: run tests
command: |
. venv/bin/activate
chmod -R 777 ./allure-2.11.0/bin/
pytest --alluredir=./allure-results tests/test_jira_api.py
pytest -n 3 --dist=loadscope -v --reruns 2 --alluredir ./allure-results tests/test_jira_api.py
- run:
name: run report
when: always
command: |
./allure-2.11.0/bin/allure generate -c
allure generate -c
- store_artifacts:
path: allure-report
destination: allure-report
Expand Down
19 changes: 12 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
allure-pytest==2.6.2
allure-python-commons==2.6.2
allure-pytest==2.5.1
allure-python-commons==2.5.1
apipkg==1.5
appdirs==1.4.0
astroid==1.4.9
atomicwrites==1.3.0
Expand All @@ -11,6 +12,7 @@ coverage==4.3.4
coveralls==1.1
crayons==0.2.0
docopt==0.6.2
execnet==1.6.0
fibonacci==1.0.0
isort==4.2.5
lazy-object-proxy==1.2.2
Expand All @@ -22,12 +24,16 @@ packaging==16.8
pluggy==0.9.0
py==1.8.0
pyparsing==2.1.10
pytest==4.4.0
pytest==3.7.2
pytest-base-url==1.4.1
pytest-html==1.20.0
pytest-metadata==1.8.0
pytest-selenium==1.16.0
pytest-forked==0.2
pytest-html==1.19.0
pytest-metadata==1.7.0
pytest-parallel==0.0.2
pytest-rerunfailures==4.1
pytest-selenium==1.14.0
pytest-variables==1.7.1
pytest-xdist==1.23.0
requests==2.13.0
restflow==0.8b0
selenium==3.141.0
Expand All @@ -36,4 +42,3 @@ urllib3==1.24.2
webdriver-manager==1.7
wrapt==1.10.8
xmltodict==0.12.0
pytest==4.4.0
9 changes: 9 additions & 0 deletions src/jira_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

created_issues = []
j = JSONFixture()
times_rerun = []


class JiraApi:
Expand Down Expand Up @@ -60,3 +61,11 @@ def delete_all_issues(self):
result = JiraApi.delete_issue(self, issue_id)
response_codes_list.append(result.status_code)
return response_codes_list

@allure.step
def rerun(self):
if len(times_rerun) == 0:
times_rerun.append(1)
return 1
else:
return 2
26 changes: 8 additions & 18 deletions tests/test_jira_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_login_to_jira(self, response, expected):
def test_post_issue(self):
response = api.post_issue("OA API Issue001", "OlegAverkin", "Low")
assert response.status_code == 201
assert "WEBINAR" in response.json().get('key')

@allure.tag('api')
@allure.title("Update issue")
Expand All @@ -31,17 +32,7 @@ def test_update_issue(self):
issue_id = response.json().get('id')
response_update = api.update_issue(issue_id, "OA API Issue002 Updated", "OlegAverkin", "Low")
assert response_update.status_code == 204

@allure.tag('api')
@allure.title("Post multiple issues")
@pytest.mark.api
@pytest.mark.parametrize("response,expected", [
(api.post_issue("OA API Issue003", "OlegAverkin", "Low"), 201),
(api.post_issue("OA API Issue004", "OlegAverkin", "Low"), 201),
(api.post_issue("OA API Issue005", "OlegAverkin", "Low"), 201),
(api.post_issue("OA API Issue006", "OlegAverkin", "Low"), 201)])
def test_post_issues(self, response, expected):
assert response.status_code == expected
api.delete_all_issues()

@allure.tag('api')
@allure.title("Missing required fields")
Expand All @@ -63,17 +54,17 @@ def test_post_issue_long_summary(self):
@allure.title("Test search issue")
@pytest.mark.api
def test_search_1_issue(self):
response = api.search_issue("Issue001")
response = api.search_issue("OAsearch1")
assert response.status_code == 200
assert response.json().get('total') == 1

@allure.tag('api')
@allure.title("Test five issue")
@pytest.mark.api
def test_search_5_issues(self):
response = api.search_issue("OA")
response = api.search_issue("OAsearch5")
assert response.status_code == 200
assert response.json().get('total') == 6
assert response.json().get('total') == 5

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

@allure.tag('api')
@allure.title("Delete all issues")
@allure.title("Random test for re-run")
@pytest.mark.api
def test_delete_all_issues(self):
response = api.delete_all_issues()
assert len(response) == 6
def test_random(self):
assert api.rerun() == 2

0 comments on commit 2e705a8

Please sign in to comment.