4 | Pytest Getting Started | Selenium Python

preview_player
Показать описание
What is Pytest
How to install and setup Pytest in project
Create and run Pytest tests
Reporting

What is Pytest
Open source Testing Framework (Library) for Python

Easy to use
Flexible & Powerful
Assertions
Command line runs
Reporting
Active community

How to install and setup Pytest in project
Step 1 - On terminal run command pip install pytest | pytest --version | pytest --help
OR
Open project > Settings > Interpreter > Add package > pytest
Step 3 - Add some tests and run

Naming conventions of pytest:
File name should start or end with “test” e.g. “test_abc” or “abc_test”
If tests are defined as methods on a class, the class name should start with “Test” e.g. TestExample
all functions of the class should start with test_

Sample pytest tests

def func(x):
return x+1

def test_1():
assert func(3) == 4

def test_2():
assert func(4) == 6

def test_3():
assert func(5) == 6

Step 4 - Group multiple tests in a class and run the class

class TestCases:

def test_1(self):
assert func(3) == 4

def test_2(self):
assert func(4) == 6

def test_3(self):
assert func(5) == 6

Step 5 - Run tests from command line

Run tests in a directory: pytest \tests\
Run tests by keyword: pytest -k login //run all tests that contain the word "login"

Step 6 - Reporting
Add pytest-html package

References:

▬▬▬▬▬▬▬

Every Like & Subscription gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can

If my work has helped you, consider helping any animal near you, in any way you can

Never Stop Learning
Raghav Pal

▬▬▬▬ USEFUL LINKS ▬▬▬▬

Pytest tutorial for beginners
How to use Pytest
Pytest for functional testing


Рекомендации по теме
Комментарии
Автор

Thank you for sharing your knowledge and experience.

flirtuall
Автор

Never mind, I see that later you returned with a solution ;) Thanks!

VAudioVideo
Автор

Hi Raghav. It would be great if you can create videos on any popular python framework with complete guideline including page object model!

fuadkhan