Posts

Pytest Tutorial - 6 | Intermediate - Parametrization in detail

Introduction In our previous tutorial, we delved into the powerful world of Pytest's parametrize feature. We discovered how it enables us to perform data-driven tests with ease. However, to truly master data-driven testing, we need to move beyond the basics and develop an intermediate understanding of this feature. In this article, we will explore what Pytest parametrize is, the parameters it supports, how it operates, and illustrate its usage with practical examples. What is the Pytest Parametrize Feature? Pytest parametrize is a versatile feature that allows you to execute the same test function multiple times with different sets of input data. This feature streamlines the process of testing various scenarios, making it a fundamental tool in software testing. Allowed Parameters The Pytest parametrize feature supports two main  argnames:  This parameter defines the names of the input arguments to your test function. It can be a string or a list of strings, specifying one or m...

Pytest Tutorial - 5 | The Basics - How to write data-driven tests?

Image
So far we have understood how to write simple tests in pytests . We also saw pytest in action. In this tutorial we will now learn how to write data driven tests. What are data driven Tests? These are those tests, which tests a functionality using various scenarios mocked through a set of test data. In order to achieve this we pass the test data from external data sources such as csv/excel/yaml/json/database/etc. Now why do we need to pass test data from an external data source? Very simple reasons: If the test data is not passed through an external data source, then everytime we add/update/remove test data, we need to update our code. One test case can be tested using multiple combinations of data to test for various conditions of validation Example 1: you can test login using 2 types of test data   Valid credentials Invalid credentials      Example 2: you can also test password change functionality with 6 types of test data : (Minimum - 1) allowed length of passwo...

Pytest Tutorial - 4 | The Basics - Testing Concepts and Types

Image
  Why this in between pytest tutorials? Dear learners, I feel that knowing the basics of Test types and concepts behind it will help each one of us in the long run of writing robust, scalable, readable and impactful tests. Let’s dive in! There are multiple types of testing which are generally performed in various IT organizations. Unit tests Integration Tests System tests (Will explore on this in separate tutorials) System integration tests (Will explore on this in separate tutorials) Pytest can help in all the above. These types of testing are fine however, when it comes to testing, we have many test cases to automate/run, be it unit test or integration or system tests. In order to manage this we need to learn test management as well. Typically in test management we  Map our tests to requirements/user stories for test coverage purposes group our tests in TEST SUITES.  A test suite is a collection of tests. You can have multiple test suites such as unit test suite/integra...

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)...