- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run a selected test from a set of tests in pytest?
We can run a selected test from a set of tests in pytest. Pytest is a test framework in python. To install pytest, we need to use the command pip install pytest. After installation, we can verify if python has been installed by the command pytest –version. The version of pytest shall be known.
Pytest can be used for creating and executing test cases. It can be used in wide range testing API, UI, database and so on. The test file of pytest has a naming convention that it starts with test_ or ends with _test keyword and every line of code should be inside a method which should have a name starting with test keyword. Also each method should have a unique name.
In order to print the console logs, we need to use the command py.test –v –s. Again, if we want to run tests from a specific pytest file, the command is py.test <filename> -v.
Let us consider a pytest file having test methods.
def test_CalculateLoan(): print("Loan calculation") def test_CalculateLease(): print("Lease calculation")
Let us consider another pytest file having test methods.
def test_CalculateRepay(): print("Loan calculation") def test_FindLease(): print("Lease search")
To execute the test methods having a particular string within its name, we need to execute the command, pytest -k <substring> -v. Here -k <substring> is the substring to look for in the test methods and v means verbose.
For our case, the command should be pytest -k Calculate –v. The test methods having Calculate in their names, shall be chosen for execution. In this case, CalculateLoan(), CalculateLease()and CalculateRepay() will be executed.
- How to group selected tests from a set of tests in pytest?
- How to execute a selected test from a collection of tests in Pytest?
- How to skip a selected test from execution in pytest?
- How to run tests using a test runner file for Cucumber?
- How to exclude a test from execution in Pytest?
- How to run a test method without reporting as passed or failed in pytest?
- How to run a specific group of tests in TestNG from command line?
- How to group test cases in Pytest?
- How to include and exclude test methods from a set of test cases in Cucumber?
- How to run Selenium tests on Chrome Browser using?
- How to run Selenium tests on Internet Explorer browser?
- How to run Selenium tests in multiple browsers one after another from C# NUnit?
- How to run test groups in TestNG?
- How to run multiple test classes in TestNG?
- How to run multiple test cases using TestNG Test Suite in Selenium?