Let us create a basic pytest example and Execute the file in possible ways.
Below are the functions which we create inside the test class file.
test_PytestExample.py
def test_methodA():
print("This is method A")
def test_methodB():
print("This is method B")
assert False
def test_methodC():
print("This is method C")
def test_methodD():
print("This is method D")
Below is the command which is used to execute pytest file test_PytestExample.py
Open the terminal and redirect to the package where test_PytestExample.py file exists and type the below command pytest.
pytest
OutPut data which generates after executing the above file.
OutPut data
admin@admin-MacBook pytest % cd pytestconcept
admin@admin-MacBook pytestconcept % pytest
============================================================================ test session starts ============================================================================
platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.8.1, pluggy-0.13.1
rootdir: /Users/admin/Documents/Skill2Lead/Tutorials/pytest/pytestconcept
plugins: rerunfailures-9.0, allure-pytest-2.8.16, ordering-0.6
collected 4 items
test_PytestExample.py .F.. [100%]
================================================================================= FAILURES ==================================================================================
_______________________________________________________________________________ test_methodB ________________________________________________________________________________
def test_methodB():
print("This is method B")
> assert False
E assert False
test_PytestExample.py:7: AssertionError
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
This is method B
========================================================================== short test summary info ==========================================================================
FAILED test_PytestExample.py::test_methodB - assert False
======================================================================== 1 failed, 3 passed in 0.08s ========================================================================
admin@admin-MacBook pytestconcept %