Skip to content

shakir-mairaj/PyTest-Automation

Repository files navigation

PyTest Automation

Pytest is a testing framework for Python. It provides a simple way to write and execute tests for your code, including unit tests, functional tests, and integration tests. Pytest makes it easy to discover and run tests, as well as to write tests in a readable and maintainable way. Pytest supports fixtures, which are reusable objects that can be used to set up test data, and it also provides a rich set of built-in assert functions to test the behavior of your code. Additionally, Pytest has a plugin system that enables users to extend its functionality with custom functionality.

Here are some of the most commonly used pytest commands:

To install pytest --- pip install pytest
Note: All pytest files and functions should either start or end with the "test" keyword

pytest - runs all tests in the current directory and subdirectories
pytest <file_name> - runs all tests in the specified file
pytest <file_name>::<function_name> - runs a specific test function in the specified file
pytest -k <expression> - runs tests whose name matches the given expression
pytest -m <marker_expression> - runs tests marked with the specified marker
pytest -x - stop after first failure
pytest -v - verbose output
pytest --tb=<style> - specify traceback style (e.g. "long" or "short")
pytest --junitxml=<file_name> - output test results to a JUnit XML file
pytest --cov=<module_name> - run tests with coverage analysis for the specified module
pytest filename --html=htmlfilename.html