PyTest Quick Start
PyTest Quick Start
Introduction
to
Pytest
Pytest Basics
• Testing Framework for Python
• API Testing
• Unit Testing
• Simple or Complex
• Class names must start with ‘Test’ and methods with ‘test’
Class TestFooBar(object):
def test_verify_something():
PyTest Basics
# smoke_test.py # smoke_test.py
or
$ py.test <options> /path/to/test/filesc
or
$ python –m pytest <options> /path/to/test/files
Selecting Specific Tests
(Markers)
Selecting Tests by Markers
# smoke_test.py # smoke_test.py
@pytest.mark.smoke @pytest.mark.smoke
def test_user_login(): Class TestUserSmoke(object):
print(“log in”)
def test_user_login():
@pytest.mark.regression print(“log in”)
def test_user_register():
print(“register”) def test_user_register():
print(“register”)
Selecting Tests by Markers
# smoke_test.py # smoke_test.py
def test_user_login():
Class TestUserSmoke(object):
print(“log in”)
def test_user_login():
def test_user_register():
print(“log in”)
print(“register”)
def test_user_register():
print(“register”)
Selecting Tests by Markers
# smoke_test.py
import pytest
@pytest.mark.smoke
@pytest.mark.fe
def test_user_login():
print(“log in”)
def test_user_register():
print(“register”)
PyTest Basics
To run the test
$ pytest -m smoke