Back to Browse

4 | Pytest Getting Started | Selenium Python

15.0K views
Jul 18, 2023
26:30

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/PLhW3qG5bs-L9Nu0MBqLs0bIdKOLjDAyjQ/edit ▬▬▬▬▬▬▬ 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/udemy-discounts/ Stories - https://automationstepbystep.com/stories/ 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/ —

Download

1 formats

Video Formats

360pmp437.9 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

4 | Pytest Getting Started | Selenium Python | NatokHD