Posts

Showing posts from August, 2022

Pytest Tutorial - 3 | The Basics - Write Tests

Image
In our previous article, we understood how to install pytest via requirements.txt. Learning Goal: In this tutorial we will start by writing some unit tests for a calculator app. After finishing this tutorial you will be able to understand How basic unit tests can be performed with the help of pytest? How does pytest work? Given 2 numbers the calculator app, it can perform below operations: Add Subtract Multiply Divide If denominator is not 0 Throw a message ( Can't divide by 0 ) if the denominator is 0. Now let’s start with writing some unit tests to validate above functionalities and see pytest in action. Prerequisites: Clone the repo in your desired location: git clone https://github.com/TheEngrNest/pytest-tutorial-3.git We will start by opening this project in PyCharm. Once you have opened the project in PyCharm,  kindly go through the contents of calculator.py inside calculator_app package.  (can be seen right above the highlighted tests package in below step’s screenshot)...

Pytest Tutorial - 2 | The Basics - Installation

Image
Dear learners, If you haven’t read my previous article - What is pytest? I would highly recommend you to read it. However if you are confident enough then let’s get started. TLDR: Skip to the last step of this article for installation notes. Prerequisites for this tutorial: I'm going to use pycharm,  however you can use your favourite IDE. Python 3.10 We will start by creating a project. Open pycharm and create new Project Name your project whatever you want, I will name it pytest_beginner_tutorial Select new environment using Virtualenv,  (new virtual environment ensures isolated development environment for our pytest tutorial) . Hit create button. Your project directory should look like below: Lets create a requirements file to handle python package installation. Right click on the project > New > File Give file name as below: Once this file is created open the file and in the first line write “pytest”. Open terminal in pycharm and run below command: (it will automat...

Pytest Tutorial - 1 | What is Pytest?

Welcome dear readers, in this series of Pytest tutorials. If you are looking for a comprehensive tutorial in automation testing using pytest, I assure you that your wait is over! To understand what pytest is, you first need to understand the basic test automation use case first. As a Test Automation engineer, you will always be writing tests for some application under test. Now, in order to execute your tests,  you may possibly need to login,  Create test data on the fly Run your tests with multiple test data sets (to possibly verify boundary value conditions/etc) Report your test results in a readable format Store the results I’m pretty sure that we test engineers are capable enough to achieve all of the above through python. And you know what, pytest is exactly created to help avoid the time spent on organizing all the above. It seamlessly helps to do all above in an elegant way. Pytest takes care of  Discovering all your tests to run Pre-requisites for your tests (log...