Single test in pytest

In this blog, we are working on how to run a single test in the Pytest file. 

As a pre-requisite we have to check whether the following dependencies or installed or not:

  1. Project setup. 
  2. 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.

What is Pytest?

Pytest is the python testing framework, which allows the user to write the python programming language for Web and API Automation. Using Pytest we can maintain the test cases in a systematic way. 

Advantages of Pytest:

  1. Can run tests in parallel. 
  2. Can run a specific test or a subset of tests 
  3. Can run the test suite. 
  4. Automatically detect tests 
  5. Skip tests 
  6. Automatically generate the reports. 

Playwright supports the Pytest Framework. We can use the same Pytest command for both Sync and Async API. 

To install Pytest we have to run the following command in the terminal. 

After the Successful installation of Pytest run pip list in terminal to check whether the Pytest is installed successfully or not.  

File Naming Convention:

After the successful installation of Pytest to run a single Pytest file, we have to follow the following syntax for file and function naming:

  • The test script file name should be either saved by test_ at the beginning of the test script file name or _test at the end of the test script file name. 

Example: – 

  • The function name in the test script should begin with test_ then only Pytest will consider it for execution. 

Example: –

Def test_Login(): 



To Run Single File:

To run the single test script in Pytest we have to pass the file name in the terminal. 

Pytest  file name 

Test Case:- 

Step 1: – Launch the Browser. 

Step 2: – Navigate to 

Step 3: – Fill the text in the input box as welcome to close ops in playwright

Step 4: – Close the page and browser. 

To run the above script in Pytest we have to run the following command in the terminal.

The command will run the test script name as

Read the next Playwright blog Here.