4 | Pytest Getting Started | Selenium Python

Pubblicato il: 18 luglio 2023
sul canale di: Automation Step by Step
9,181
140

All Free Tutorials - https://AutomationStepByStep.com/
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 2 - Create directory tests and under it create a pytest file test_demo1.py
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 file: pytest \tests\test_demo1.py
Run tests in a directory: pytest \tests\
Run tests by keyword: pytest -k login //run all tests that contain the word "login"
Run tests using python: python -m pytest \tests\test_demo1.py

Step 6 - Reporting
Add pytest-html package
Use command: pytest .\tests\test_demo1.py --html=report1.html

References:
Python for Beginners - https://studio.youtube.com/playlist/P...

▬▬▬▬▬▬▬

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 ▬▬▬▬

Ask Raghav - https://bit.ly/2CoJGWf

Shorts Eng - https://bit.ly/3H9bifV
Shorts Hindi - https://bit.ly/3XY7XqN

GitHub Repositories - https://github.com/Raghav-Pal
Udemy - https://automationstepbystep.com/udem...
Stories - https://automationstepbystep.com/stor...
Sunday Special - https://bit.ly/2wB23BO

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

References - https://docs.pytest.org/en/7.3.x/



In questa pagina del sito puoi guardare il video online 4 | Pytest Getting Started | Selenium Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Automation Step by Step 18 luglio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 9,181 volte e gli è piaciuto 140 spettatori. Buona visione!