September 6, 2020

Advanced fixtures with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Now letā€™s create another test - it will test integration between our 2 components that talk to external systems - API and database cache. Letā€™s test that when we query a number twice - we call API only once that the result is saved to the database and fetched from it on the second call. Read more

September 6, 2020

Hello, World!

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins In this course, we will be working on a mobile phone number validation application. The application: Accepts a number as input For every number in the list Normalize the number Check cache if this number was validated before If itā€™s not in cache call external service REST API to validate the number print the normalized number and the result of validation Letā€™s start with the Normalize step. Read more

September 6, 2020

Pytest plugins

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins There are lot of plugins in pytest ecosystem. Some of the widely used are listed here All the plugins can be installed with pip and invoked by providing an argument to pytest executable. pytest-cov This plugin calculates test coverage - how much of our code is covered by test. Read more

September 6, 2020

Selecting tests with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Let’s add another requirement for our normalize function - it will raise an exception if the number contains a letter, or if a plus sign is not at the beginning. Now letā€™s think a bit about the design of the application. Read more

September 6, 2020

Test driven Development

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Is it better to write test cases after the code has been written or beforehand? Usually, itā€™s cheaper to detect bugs as early as possible in the development process. And writing test cases first will minimize the time between when a defect is inserted into the code and when the defect is detected and removed. Read more

September 6, 2020

Testing database with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins We are going to use a database in our number testing application as a cache for API call results - API calls can be costly and we donā€™t want to check the same number twice against it. Read more

September 6, 2020

Testing HTTP client with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Now letā€™s move to checking if the number exists or not. For that, we are going to employ a 3rd party API. According to API docs: Itā€™s a REST API We need to use HTTP GET We provide a number in query parameters The result is a json {ā€˜existingā€™: True | False} Iā€™m going to create this 3rd party API myself and run it from my local environment so we can see the access logs. Read more

September 6, 2020

Types of tests

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins There are many types of tests. Brian Marick came up with this chart, which is widely used to show which types you should care about in order to deliver a high-quality application. In this diagram, he categorized tests according to whether they are business-facing or technology-facing, and whether they support the development process or are used to critique the project. Read more

September 6, 2020

Why testing is important

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Testing makes our code flexible, reliable and reusable. Flexible If you donā€™t have tests for your code - every change to the code is a possible bug. Thus, developers fear making changes and implementing new features, no matter how flexible the architecture of the application is. Read more

© Alexey Smirnov 2023