Skip to content

shashikumarraja/pytest_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PYTEST TUTORIAL

python 2.7 pytest 3.6.4 allure_pytest 2.5.0 pytest_html 1.19.0 xdist 1.22.5 Build Status Coverage Status Updates Python 3

Contains pytest scripts which helps in understanding different pytest functionalities and features.

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.

An example of a simple test:

# content of test_sample.py
def inc(x):
    return x + 1
#make sure the test function's name starts with 'test_'
def test_answer():
    assert inc(3) == 5

How to Run the project?

  1. Clone/download this repo

  2. Install all the dependencies using-

pip install -r requirements.txt
  1. Tests are located inside src/tests/
pytest src/tests
  1. To run tests and generate html report
pytest src/tests --html=report.html --self-contained-html

alt text

  1. To run tests and generate allure report
#make sure report directory exists in the root folder
pytest src/tests --alluredir=report/

#To view the allure report
allure serve report/

alt text

  1. To run tests with code coverage report
pytest --cov=src --verbose

alt text

  1. To run tests with multiple cpu cycles(will speed up the test execution by running them in parallel)
pytest src/tests -n 5
  1. To fix liniting errors the project uses autopep8. To modify a file in place (with aggressive level 2):
$ autopep8 --in-place --aggressive --aggressive <filename>

Releases

No releases published

Packages

No packages published

Languages