In this blog, we are working on how to run the test suite or group of test cases in the Pytest file.
Pre-requisites:
As a pre-requisite we have to check whether the following dependencies are installed or not:
- Project setup.
- Run pip list in PyCharm terminal to check whether playwright is installed or not.

As shown in the above picture Playwright should be installed in the project.
If the Playwright is not installed refer to Web Automation Testing using Playwright.
Playwright supports the Pytest Framework. We can use the same Pytest command for both Sync and Async APIs.
Installation:
To install Pytest we have to run the following command in the terminal.
pip install Pytest-playwright
After the Successful installation of Pytest run pip list in terminal to check whether the Pytest is installed successfully or not.

If Pytest is not installed then check out the blog on How to run the single test case in Pytest.
To run the test suit or group of tests we have to follow the following approach :
- To Run Test Suit:
The file name which starts either with test_ or ends with _test in a directory is considered for running the test suit. We have to provide the directory name following the Pytest command.
Syntax: Pytest directory name
- Group the test script:
To group the test cases/scripts we use the Decorator or Annotation I.e Pytest markers. By marking the test case with a specific keyword, we can run a group of test cases.
For Example: – If we want to perform sanity then we have to mark the test cases with the keyword named sanity.

To Run the marked test cases we have to use the command as –m followed by the marker name or keyword.

Test Case:
Step 1: – Launch the Browser.
Step 2: – Navigate to https://www.google.com
Step 3: – Execute a few test cases in a group.
Step 4: – Close the browser.

Code Explanation:
In the above code snippet:
- We have marked two test case functions as sanity using Pytest custom markers. When we run the command in the terminal as pytest –m sanity then, Pytest will select only those test functions which are marked by the keyword as sanity and execute them.
- If you encounter logs in the terminal related to the custom markers then we should register our custom markers in pytest.ini file as shown below.

Read the next Playwright blog Here.