
Why use pytest
pytest history
What are pytest's must know features
Here we will learn the very basics of pytest by running very simple tests.
We will cover here:
Pytest test runner
Skip, SkipIf
Xfail
Which pytest tests are executed
How pytest works
Note that this lecture is not committed to the repository because it is very basic
Here we will learn the very basics of pytest by running very simple tests.
We will cover here:
Fixtures
Parametrize
Asserting Exceptions
Note that this lecture is not committed to the repository because it is very basic
The Differences Between Unit Testing, Integration Testing And Functional Testing
Unit testing means testing individual modules of an application in isolation (without any interaction with dependencies) to confirm that the code is doing things right.
Integration testing means checking if different modules are working fine when combined together as a group.
Functional testing means testing a slice of functionality in the system (may interact with dependencies) to confirm that the code is doing the right things.
Here I describe how to setup our project with bitbucket.
How to signup (free tier)
create a git repository to work with
configure repository it with SSH keys
Here we will install pipenv to be our package manager.
what is pipenv
We will learn how to use it to install the packages we need for this course
discover some cool useful commands pipenv is offering us.
Reviewing our fully functional django web server we are going to build in this course
Create a django project
Create our companies service
Creating a Company Django model to represent our Companies table in our database
Creating a complete REST API with a few lines of code using Django Rest Framework
Using postman to manually test our django application and database constraints
Writing our first unit tests for our cool API
Pytest
Unittest
Using unittest test classes to avoid duplicate code
How can pytest runs unittest tests
@pytest.mark.skip - a mark to skip a test with the pytest test runner
@pytest.mark.xfail - a mark to not fail the test run if the marked test failed (for falky tests)
How to write pytest tests that assert an exception was raised
How to write tests that assert log messages
How to use the pytest test runner
pytest common flags to run custom tests
Which pytest tests are executed
Testing Django applications
Django native test framework
Pytest Django
Test databases
Why pytest is better than unittest
Refactor our test suite from unittest style to pytest native
Comparing our unittest test suite with our pytest native test suite
Why pytest is better than unittest
What is continuous integration (CI) ?
Where did CI come from?
How can we practice CI?
What are bitbucket pipelines
Create bitbucket pipelines which will run our tests every push
What are bitbucket environment variables
Defining bitbucket environment variables to decouple our environments (dev and remote)
Adding an email endpoint /send-email
Send an email to our predefined email when posting to the endoint
Convert all tests to use only pytest features
Pytest-django special fixtures: client, settings
What are we going to do in this section?
How to use pytest parametrize and run tests with different inputs
Here we are implementing from zero the pytest parametrize feature.
This will help us understand what is pytest doing under the hood when we use pytest paramterize.
The principal here seem complex, but this is just creating a decorator which receives arguments.
Using caching to solve fibonacci
Here we will add all the tests we added so far, to our bitbucket continuous integration pipeline
Here we are writing a pytest fixture that will help us keep track on our test's runtime.
The final version of our fibonacci function, using dynamic programming.
This is the best solution for this problem which is has O(n) runtime complexity and O(1) space complexity.
How to write a performance test.
We will write a test that if the runtime of the test exceeds the runtime threshold we define, then we fail our tests.
This way, we can discover if we introduced bottlenecks to our codebase.
Why did we implement the performance test?
We can simply use the pytest-timeout plugin which basically performs the same.
This is a MUST course for anyone who cares about testing.
I teach the ins and outs of pytest while building a real-world Django application (including a continuous integration system in bitbucket).
In this course, we will build a very simple Django server, I will teach just enough Django so that we will be able to build the application and then focus on testing it.
We will together test the application from all angels - Unit tests, integration tests, API tests, end-to-end tests , and performance tests with (a total of over 40 tests)
You will end up with a complete CI system that integrates bitbucket cloud pipelines, slack messaging, and allure reporting.
Every time we will make a push, the CI system will run our tests and will notify us if the build passed/failed.
In this course, we go in-depth, and we will even implement together (from scratch) some of pytest's features so that we will know what happens under the hood when pytest is running our tests.
This is not an entry-level course; basic knowledge of python is needed
You will learn:
Pytest features (in-depth)
Fixtures
Markers
Parametrize
Skip, xfail
Pytest.ini
Pytest-django
Pytest-cov
pytest-xdist
unittest library, mocks
Requests library
Django (just enough to build a web server)
Rest API
Models, Migrations
Views
Serializers
SQLite3 DB
Email backends
Continuous Integration (in-depth)
Bitbucket pipelines
Bitbucket environment variables
Parallel steps
Docker
Slack messaging integration
Allure Reporting
Testing (In-depth)
Unit tests
Mocking. Patching, Stubs
Integration tests
Performance tests
Testing environments
Python best practice
Virtual environments: pipenv
Pipfile
Type hinting
Black formatter
.env File
Recreating react our projects UI (No prior knowledge is needed