Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Learn hands-on test automation with Python! Set up pytest & Playwright for the unit, API, and UI tests. Start automating tests efficiently.

TestMu AI
January 27, 2026
Python is a fantastic choice for automating tests. Its straightforward syntax and extensive package library make it perfect for test automation. This hands-on session dives into testing with Python, skipping the slides, and focusing on live coding.The session covers everything from building projects with pytest and Playwright to writing unit, API, and UI tests together. After this session, you’ll be equipped to begin automating tests using Python and will have additional resources for further learning.
Many developers want to learn how to automate tests effectively using Python due to its simplicity and versatile package ecosystem. However, finding practical guidance can be challenging. This session addresses this gap by providing a live coding demonstration and guiding participants through setting up a testing project with pytest and Playwright. The session covers writing different types of tests, ultimately empowering attendees to automate their tests using Python confidently.
Andrew Knight, nicknamed “Pandy,” is the Automation Panda. He likes helping folks make good software. He’s into open-source software and is a Playwright Ambassador. Pandy makes software tools and is writing a book about testing. He’s also into old Volkswagens. You can see his blog at AutomationPanda.com and find him on Twitter as @AutomationPanda.
If you couldn’t catch all the sessions live, don’t worry! You can access the recordings at your convenience by visiting the TestMu AI YouTube Channel.
Andrew’s session gave the impression to his audience that coding and testing are not complicated. He started by providing a basic overview of Python with live coding, covering all the essential aspects anyone would need to know.
He highlighted a few advantages of why he prefers using Python. He spoke about how great and supportive the large community of Python is. The syntax is easy because it’s concise and powerful, and it’s easy to import anything you require.
With all these advantages, let’s jump further into the session with Andrew Knight.
Andrew shared the learning path with his audience, where they could gain more knowledge on Python Testing.

Andrew mentioned that in MacOS, Python is already installed. To check if Python is pre-installed on the machine, run this command to verify.
python --version

You can install Python by following the installation instructions from the official Python site.
Andrew navigated and launched the Python project folder in VS Code, as he preferred using VS Code for Python coding. This was due to the helpful extension provided by Microsoft for Python development.

Andrew had a Python extension installed already. He guided his audience on installing the Python extension if it was not installed.

Click on the Extension icon from the left menu items on VS Code, then on the search bar, type in Python, and then click on the Install button from the right side details page.

Andrew mentioned that Microsoft maintains the Python extension, a go-to extension with a large community and good support. He also mentioned that its simple syntax made Python a good starting point.
Andrew preferred to use pytest as his testing framework as it provides unique advantages. Pytest comes with standard Python libraries called unittest. Before he delved into the specifics of the directory structure, he informed the audience that it was essential to grasp some key concepts related to the unittest.
The unittest module is a pre-existing library in Python designed for testing individual parts of code. It enables developers to create and run consistent tests, ensuring their code works as intended and stays dependable over time.
Andrew further guided his audience through the step-by-step procedure and gave an insight into how easy it can be to write Python code and to test using the pytest framework.




Andrew explained that this simple code is a pytest code, with no need to write separate classes, methods, or test functions. He further explained each line of the code.
In short, the code sets up a test to confirm if adding 1 and 1 equals 2. If it’s true, the test passes; if not, it fails.
To run the above pytest code, the installation of pytest is needed. In some other testing environments, like when working with JavaScript, use npm, and for Java, there is a Maven project where all the Maven dependencies are together. Likewise, to run a Python project, There is a need to create a Virtual Environment.
Virtual Environment stores all the packages on which the Python project depends; rather than making it global for your whole machine, creating a virtual environment can make it local for your project. Andrew preferred to use the local Virtual Environment for this live coding session.









Once the command is executed, the summary of the test run is given, whether pass or fail.
Andrew further explained what the test command displays in the terminal.

Andrew wrote another test script that checks if value a + value b == value c. He explained each line of code in further detail.



Andrew further involved Playwright in his test script, nothing too fancy, with basic details on installing third-party Playwright libraries. He installed Playwright to write the next set of test instructions to run a Playwright script with Python.
Andrew used the pytest command to install the Playwright library.

Now run the playwright install command to install the Playwright browser projects, which are three of these: Chrome, Firefox, and WebKit.

Andrew created a new project file, test_web_stuff, under the same folder called tests.

He wrote a set of Python instructions where he automated the flow of visiting Playwright’s official website.


These instructions use the Playwright library to perform automated testing on a webpage.
The test aims to check if the webpage’s title contains the word, Playwright.
The command is the same as before: pytest followed by the file and folder names if required.


He used headed and slowmo and gave some milliseconds to grab the screen load, as the original test ran in 16 milliseconds.

It was a wonderful warp-up by Andrew, and he hopes his audience learned and enjoyed the live coding session. It was a great opportunity for his audience to get hands-on experience with Python Testing. He ended the session with some Q&A’s
Have you got more questions? Drop them on the TestMu AI Community.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance