SlideShare a Scribd company logo
1 of 61
Download to read offline
Pytest
recommendations and basic
packages for testing in
Python and Django
Andreu Vallbona
PyBCN June 2019
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Who am I
Andreu Vallbona @avallbona
Bachelor degree in computer science
Web developer at APSL, Mallorca, Spain
Mainly developing with Python and Django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
What we do at APSL
Web development
Systems engineering - devops
Data science
Mobile apps
Consulting and formation
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Advantages
Advantages
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Advantages
● Ensure the quality of the code
● Confidence when changes/refactors are made
● Facilitate Python and / or Django version
upgrades
● Ease in database system changes (e.g.: from
mysql to postgres)
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Why pytest?
Why pytest?
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Why pytest?
● Very little boilerplate code, which makes tests
easy to write and understand
● Can easily be extended with plugins
● Parametrize any test and cover all uses of a
unit without code duplication
● Uses fixtures as a method to recreate previous
scenario
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Why pytest?
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Recommendations
Recommendations
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Recommendations
● Test database in local and / or memory
● Be careful with the signals of Django
● Mock external services
● Concurrent execution
● Review PEP8
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Recommendations
● Do not overly sophisticate the tests
● Self-contained and independent tests
● Use parametrize
● Use fixtures
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Fixtures are objects/dependencies that we predefine and can then be used
by our test functions. You can define different scopes:
● function level: runs once per test
● class level: runs once per test class
● module level: runs once per per module
● session level: runs once per session
fixtures
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Fixtures can be parametrized
fixtures
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Fixtures can be autoinjected to test functions
fixtures
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugins
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest plugin that gives us a whole series of helpers and fixtures very useful
to test projects implemented in Django. Among others we can highlight:
● django_db - gives access to the database
● rf - request factory
● client - test client
● admin_client - authenticated test client
● admin_user - authenticated superuser
● settings - access to the django settings
● mailoutbox - mailbox where to test the sending of emails
pytest-django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Some key features of this plugin are:
● allow us to set a settings for the test scenario
● allow us to reuse the test database between test sessions
● allow us not to execute the migrations when creates the test database, it
create the test database directly from the models
pytest-django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
●
pytest-django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Allow us to populate easily the database with initial test data
pytest-django
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Package that helps us to easily create fixtures based on django models very
easily
● field values are generated automatically
● random content of the fields but can be specified individually
● You can create objects:
○ in memory (mommy.prepare) useful for unit tests model methods
○ persistent (mommy.make) useful for integration tests
● you can define relationships between objects (fk, m2m)
● you can define recipes, which are like templates
● sequence fields can be defined
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Giving the following model:
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
We could generate an instance of it with:
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
and then use it in a test:
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
example of sequence fields
that would generate 3 instances of the model Administrator and the value of
the name field would be respectively
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
custom generator for specific fields types
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
model mommy or factoryboy
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
model mommy or factoryboy
model-mommy
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugin that helps us to use the fixtures in lazy mode, which allows us, for
example, to use the fixtures as parameters with the parametrize.
pytest-lazy-fixture
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugin that helps us to use the fixtures in lazy mode, which allows us, for
example, to use the fixtures as parameters with the parametrize.
pytest-lazy-fixture
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
This plugin installs a mocker fixture which is a thin-wrapper around the
patching API provided by the mock package.
Allows us to patch a certain function or method in order to be able to test
our logic given an specific mocked result.
E.g. Test calls to external services, such as a call to an external API.
pytest-mock
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Given a certain method
pytest-mock
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
And an expected result
pytest-mock
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
We can mock the method as:
pytest-mock
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugin that helps us verify that we do not leave any breakpoint inserted in our
code. It analyzes the Abstract Syntax Tree of our code.
pytest-checkipdb
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
And warn us
pytest-checkipdb
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugin that helps us detect which part of our code is not yet "covered" by the
tests. Allows us to generate reports to easily see untested parts
pytest-cov
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Small case example without testing
pytest-cov
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Plugin that helps us to ensure that our code follows a style guide, for
example, in the case of python, the PEP8
pytest-flake8
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-sugar
Plugin that helps us to change the look & feel of the pytest output
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
freezegun
Package that helps us to "freeze" time. If we have methods that makes use
of the functions:
datetime.datetime.now(), datetime.datetime.utcnow(), datetime.date.today(),
time.time(), time.localtime(), time.gmtime(), time.strftime()
Will always return the moment (date and / or time) in which they have been
frozen.
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
freezegun
Simple example
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
freezegun
We can generate data
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
freezegun
and then check it
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-eradicate
Plugin that detect if we left commented code. Is able to differentiate
commented code from real comments.
Before executing pytest --eradicate
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-eradicate
Plugin that detect if we left commented code. Is able to differentiate
commented code from real comments.
After executing pytest --eradicate
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-eradicate
Plugin that detect if we left commented code. Is able to differentiate
commented code from real comments.
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-xdist
Plugin that allows us to run tests in parallel, allows us to reduce the total
execution time.
It is mandatory that the tests are completely self-contained for the use of
xdist.
When tests are invoked with xdist, pytest-django will create a separate test
database for each process. Each test database will be given a suffix
(something like “gw0”, “gw1”) to map to a xdist process.
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-xdist
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-xdist
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
Package that helps us generate data random for our specification or data
model.
Helps us to test that our code works for any value within a range and not
only for specific cases.
hypothesis
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
hypothesis
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
hypothesis
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-watch
It helps us to re-launch, automatically, the tests when changes have been
detected in the project files
Allows us to execute commands before and after the execution of the tests
and also commands depending on the success or failure of the tests
We use it in combination with the following plugin, pytest-testmon
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-testmon
Select and re-execute only the tests affected by the latest changes, whether
they are changes in business classes or in the tests themselves
https://www.youtube.com/watch?v=1xahPJ_LNXM&feature=youtu.be
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-testmon
Select and re-execute only the tests affected by the latest changes, whether
they are changes in business classes or in the tests themselves
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-splinter
Plugin that allow us to execute browser session for the execution of
functional tests
It gives us a bunch of fixtures
Allow to capture the screen when an error has ocurred
It allows us to execute the tests on remote servers (e.g.: sauce labs)
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-splinter
Allows the execution of javascript inside the test itself
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-splinter
Test example
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Plugins
pytest-splinter
Test example
Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django
Thanks
That’s all.
Thank you!
Questions?
@avallbona

More Related Content

What's hot

International organizations of ipr
International organizations of iprInternational organizations of ipr
International organizations of iprNalamVaishnavi
 
はじめてのdocker
はじめてのdockerはじめてのdocker
はじめてのdockerat grandpa
 
mpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psimpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psihexiay
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMSherif Mousa
 
Introduction to the Compliance Driven Development (CDD) and Security Centric ...
Introduction to the Compliance Driven Development (CDD) and Security Centric ...Introduction to the Compliance Driven Development (CDD) and Security Centric ...
Introduction to the Compliance Driven Development (CDD) and Security Centric ...VMware Tanzu
 
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtc
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtcYahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtc
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtcYahoo!デベロッパーネットワーク
 
serverspecを使用したサーバ設定テストの実例
serverspecを使用したサーバ設定テストの実例serverspecを使用したサーバ設定テストの実例
serverspecを使用したサーバ設定テストの実例Koichi Shimozono
 
Intellectaul property right
Intellectaul property rightIntellectaul property right
Intellectaul property rightkoach1787
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentationnishantsri
 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linuxSreenatha Reddy K R
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsAhmed El-Arabawy
 
Intro to NSM with Security Onion - AusCERT
Intro to NSM with Security Onion - AusCERTIntro to NSM with Security Onion - AusCERT
Intro to NSM with Security Onion - AusCERTAshley Deuble
 
Equinix osaka multi-cloud_day20190621
Equinix osaka multi-cloud_day20190621Equinix osaka multi-cloud_day20190621
Equinix osaka multi-cloud_day20190621Kiyomichi Arai
 
IX事業者とインターネットの未来
IX事業者とインターネットの未来IX事業者とインターネットの未来
IX事業者とインターネットの未来Yoshiki Ishida
 
カスタムブロックで自作モジュールをUIFlow対応にする
カスタムブロックで自作モジュールをUIFlow対応にするカスタムブロックで自作モジュールをUIFlow対応にする
カスタムブロックで自作モジュールをUIFlow対応にするKenta IDA
 

What's hot (20)

International organizations of ipr
International organizations of iprInternational organizations of ipr
International organizations of ipr
 
はじめてのdocker
はじめてのdockerはじめてのdocker
はじめてのdocker
 
X lite3.0 user-guide (1)
X lite3.0 user-guide (1)X lite3.0 user-guide (1)
X lite3.0 user-guide (1)
 
mpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psimpeg2ts1_es_pes_ps_ts_psi
mpeg2ts1_es_pes_ps_ts_psi
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
Introduction to the Compliance Driven Development (CDD) and Security Centric ...
Introduction to the Compliance Driven Development (CDD) and Security Centric ...Introduction to the Compliance Driven Development (CDD) and Security Centric ...
Introduction to the Compliance Driven Development (CDD) and Security Centric ...
 
DNSのRFCの歩き方
DNSのRFCの歩き方DNSのRFCの歩き方
DNSのRFCの歩き方
 
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtc
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtcYahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtc
Yahoo! JAPANのIaaSを支えるKubernetesクラスタ、アップデート自動化への挑戦 #yjtc
 
KubeVirt 201 How to Using the GPU
KubeVirt 201 How to Using the GPUKubeVirt 201 How to Using the GPU
KubeVirt 201 How to Using the GPU
 
serverspecを使用したサーバ設定テストの実例
serverspecを使用したサーバ設定テストの実例serverspecを使用したサーバ設定テストの実例
serverspecを使用したサーバ設定テストの実例
 
Intellectaul property right
Intellectaul property rightIntellectaul property right
Intellectaul property right
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Access control list acl - permissions in linux
Access control list acl  - permissions in linuxAccess control list acl  - permissions in linux
Access control list acl - permissions in linux
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
 
Intro to NSM with Security Onion - AusCERT
Intro to NSM with Security Onion - AusCERTIntro to NSM with Security Onion - AusCERT
Intro to NSM with Security Onion - AusCERT
 
Equinix osaka multi-cloud_day20190621
Equinix osaka multi-cloud_day20190621Equinix osaka multi-cloud_day20190621
Equinix osaka multi-cloud_day20190621
 
IX事業者とインターネットの未来
IX事業者とインターネットの未来IX事業者とインターネットの未来
IX事業者とインターネットの未来
 
カスタムブロックで自作モジュールをUIFlow対応にする
カスタムブロックで自作モジュールをUIFlow対応にするカスタムブロックで自作モジュールをUIFlow対応にする
カスタムブロックで自作モジュールをUIFlow対応にする
 
Windows Registry
Windows RegistryWindows Registry
Windows Registry
 
BasicLinux
BasicLinuxBasicLinux
BasicLinux
 

Similar to PyBCN - Pytest: recomendaciones, paquetes básicos para testing en Python y Django

DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest Inexture Solutions
 
Py Day Mallorca - Pipenv - Python Dev Workflow for Humans
Py Day Mallorca  - Pipenv - Python Dev Workflow for HumansPy Day Mallorca  - Pipenv - Python Dev Workflow for Humans
Py Day Mallorca - Pipenv - Python Dev Workflow for HumansAndreu Vallbona Plazas
 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaEdureka!
 
PyBCN - pipenv - python dev workflow for humans
PyBCN - pipenv - python dev workflow for humansPyBCN - pipenv - python dev workflow for humans
PyBCN - pipenv - python dev workflow for humansAndreu Vallbona Plazas
 
High scalable applications with Python
High scalable applications with PythonHigh scalable applications with Python
High scalable applications with PythonGiuseppe Broccolo
 
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74Ivy Rueb
 
Intro To JavaScript
Intro To JavaScriptIntro To JavaScript
Intro To JavaScriptIvy Rueb
 
What We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
What We Learned Building an R-Python Hybrid Predictive Analytics PipelineWhat We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
What We Learned Building an R-Python Hybrid Predictive Analytics PipelineWork-Bench
 
Scientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataScientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataGael Varoquaux
 
Master Python.pdf
Master Python.pdfMaster Python.pdf
Master Python.pdfUncodemy
 
Python Certification | Data Science with Python Certification | Python Online...
Python Certification | Data Science with Python Certification | Python Online...Python Certification | Data Science with Python Certification | Python Online...
Python Certification | Data Science with Python Certification | Python Online...Edureka!
 
Complete python toolbox for modern developers
Complete python toolbox for modern developersComplete python toolbox for modern developers
Complete python toolbox for modern developersJan Giacomelli
 
Foshan Rayven lighting Co.,Ltd
Foshan Rayven lighting Co.,LtdFoshan Rayven lighting Co.,Ltd
Foshan Rayven lighting Co.,LtdCaesar Chan
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem vAkash Rajguru
 
DA 592 - Term Project Report - Berker Kozan Can Koklu
DA 592 - Term Project Report - Berker Kozan Can KokluDA 592 - Term Project Report - Berker Kozan Can Koklu
DA 592 - Term Project Report - Berker Kozan Can KokluCan Köklü
 
Introduction to development with Django web framework
Introduction to development with Django web frameworkIntroduction to development with Django web framework
Introduction to development with Django web frameworkSammy Fung
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Edureka!
 
Django Article V0
Django Article V0Django Article V0
Django Article V0Udi Bauman
 

Similar to PyBCN - Pytest: recomendaciones, paquetes básicos para testing en Python y Django (20)

DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest
 
Py Day Mallorca - Pipenv - Python Dev Workflow for Humans
Py Day Mallorca  - Pipenv - Python Dev Workflow for HumansPy Day Mallorca  - Pipenv - Python Dev Workflow for Humans
Py Day Mallorca - Pipenv - Python Dev Workflow for Humans
 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | Edureka
 
PyBCN - pipenv - python dev workflow for humans
PyBCN - pipenv - python dev workflow for humansPyBCN - pipenv - python dev workflow for humans
PyBCN - pipenv - python dev workflow for humans
 
High scalable applications with Python
High scalable applications with PythonHigh scalable applications with Python
High scalable applications with Python
 
Django
DjangoDjango
Django
 
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74
Deck 8983a1d9-68df-4447-8481-3b4fd0de734c-9-52-74
 
Intro To JavaScript
Intro To JavaScriptIntro To JavaScript
Intro To JavaScript
 
What We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
What We Learned Building an R-Python Hybrid Predictive Analytics PipelineWhat We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
What We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
 
Scientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataScientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of data
 
Master Python.pdf
Master Python.pdfMaster Python.pdf
Master Python.pdf
 
Python Certification | Data Science with Python Certification | Python Online...
Python Certification | Data Science with Python Certification | Python Online...Python Certification | Data Science with Python Certification | Python Online...
Python Certification | Data Science with Python Certification | Python Online...
 
Complete python toolbox for modern developers
Complete python toolbox for modern developersComplete python toolbox for modern developers
Complete python toolbox for modern developers
 
Django
Django Django
Django
 
Foshan Rayven lighting Co.,Ltd
Foshan Rayven lighting Co.,LtdFoshan Rayven lighting Co.,Ltd
Foshan Rayven lighting Co.,Ltd
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
DA 592 - Term Project Report - Berker Kozan Can Koklu
DA 592 - Term Project Report - Berker Kozan Can KokluDA 592 - Term Project Report - Berker Kozan Can Koklu
DA 592 - Term Project Report - Berker Kozan Can Koklu
 
Introduction to development with Django web framework
Introduction to development with Django web frameworkIntroduction to development with Django web framework
Introduction to development with Django web framework
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
 

More from Andreu Vallbona Plazas (7)

Localhost to the internet
Localhost to the internetLocalhost to the internet
Localhost to the internet
 
Pipenv python dev workflow for humans
Pipenv  python dev workflow for humansPipenv  python dev workflow for humans
Pipenv python dev workflow for humans
 
Apsl attrs
Apsl   attrsApsl   attrs
Apsl attrs
 
Apsl pycharm + docker
Apsl   pycharm + dockerApsl   pycharm + docker
Apsl pycharm + docker
 
Apsl testing
Apsl   testingApsl   testing
Apsl testing
 
Apsl translation manager
Apsl   translation managerApsl   translation manager
Apsl translation manager
 
Pytest - testing tips and useful plugins
Pytest - testing tips and useful pluginsPytest - testing tips and useful plugins
Pytest - testing tips and useful plugins
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

PyBCN - Pytest: recomendaciones, paquetes básicos para testing en Python y Django

  • 1. Pytest recommendations and basic packages for testing in Python and Django Andreu Vallbona PyBCN June 2019
  • 2. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Who am I Andreu Vallbona @avallbona Bachelor degree in computer science Web developer at APSL, Mallorca, Spain Mainly developing with Python and Django
  • 3. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django What we do at APSL Web development Systems engineering - devops Data science Mobile apps Consulting and formation
  • 4. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Advantages Advantages
  • 5. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Advantages ● Ensure the quality of the code ● Confidence when changes/refactors are made ● Facilitate Python and / or Django version upgrades ● Ease in database system changes (e.g.: from mysql to postgres)
  • 6. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Why pytest? Why pytest?
  • 7. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Why pytest? ● Very little boilerplate code, which makes tests easy to write and understand ● Can easily be extended with plugins ● Parametrize any test and cover all uses of a unit without code duplication ● Uses fixtures as a method to recreate previous scenario
  • 8. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Why pytest?
  • 9. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Recommendations Recommendations
  • 10. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Recommendations ● Test database in local and / or memory ● Be careful with the signals of Django ● Mock external services ● Concurrent execution ● Review PEP8
  • 11. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Recommendations ● Do not overly sophisticate the tests ● Self-contained and independent tests ● Use parametrize ● Use fixtures
  • 12. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Fixtures are objects/dependencies that we predefine and can then be used by our test functions. You can define different scopes: ● function level: runs once per test ● class level: runs once per test class ● module level: runs once per per module ● session level: runs once per session fixtures
  • 13. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Fixtures can be parametrized fixtures
  • 14. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Fixtures can be autoinjected to test functions fixtures
  • 15. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugins
  • 16. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest plugin that gives us a whole series of helpers and fixtures very useful to test projects implemented in Django. Among others we can highlight: ● django_db - gives access to the database ● rf - request factory ● client - test client ● admin_client - authenticated test client ● admin_user - authenticated superuser ● settings - access to the django settings ● mailoutbox - mailbox where to test the sending of emails pytest-django
  • 17. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Some key features of this plugin are: ● allow us to set a settings for the test scenario ● allow us to reuse the test database between test sessions ● allow us not to execute the migrations when creates the test database, it create the test database directly from the models pytest-django
  • 18. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins ● pytest-django
  • 19. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-django
  • 20. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Allow us to populate easily the database with initial test data pytest-django
  • 21. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Package that helps us to easily create fixtures based on django models very easily ● field values are generated automatically ● random content of the fields but can be specified individually ● You can create objects: ○ in memory (mommy.prepare) useful for unit tests model methods ○ persistent (mommy.make) useful for integration tests ● you can define relationships between objects (fk, m2m) ● you can define recipes, which are like templates ● sequence fields can be defined model-mommy
  • 22. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Giving the following model: model-mommy
  • 23. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins We could generate an instance of it with: model-mommy
  • 24. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins and then use it in a test: model-mommy
  • 25. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins example of sequence fields that would generate 3 instances of the model Administrator and the value of the name field would be respectively model-mommy
  • 26. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins custom generator for specific fields types model-mommy
  • 27. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins model mommy or factoryboy model-mommy
  • 28. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins model mommy or factoryboy model-mommy
  • 29. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugin that helps us to use the fixtures in lazy mode, which allows us, for example, to use the fixtures as parameters with the parametrize. pytest-lazy-fixture
  • 30. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugin that helps us to use the fixtures in lazy mode, which allows us, for example, to use the fixtures as parameters with the parametrize. pytest-lazy-fixture
  • 31. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins This plugin installs a mocker fixture which is a thin-wrapper around the patching API provided by the mock package. Allows us to patch a certain function or method in order to be able to test our logic given an specific mocked result. E.g. Test calls to external services, such as a call to an external API. pytest-mock
  • 32. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Given a certain method pytest-mock
  • 33. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins And an expected result pytest-mock
  • 34. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins We can mock the method as: pytest-mock
  • 35. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugin that helps us verify that we do not leave any breakpoint inserted in our code. It analyzes the Abstract Syntax Tree of our code. pytest-checkipdb
  • 36. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins And warn us pytest-checkipdb
  • 37. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugin that helps us detect which part of our code is not yet "covered" by the tests. Allows us to generate reports to easily see untested parts pytest-cov
  • 38. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Small case example without testing pytest-cov
  • 39. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Plugin that helps us to ensure that our code follows a style guide, for example, in the case of python, the PEP8 pytest-flake8
  • 40. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-sugar Plugin that helps us to change the look & feel of the pytest output
  • 41. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins freezegun Package that helps us to "freeze" time. If we have methods that makes use of the functions: datetime.datetime.now(), datetime.datetime.utcnow(), datetime.date.today(), time.time(), time.localtime(), time.gmtime(), time.strftime() Will always return the moment (date and / or time) in which they have been frozen.
  • 42. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins freezegun Simple example
  • 43. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins freezegun We can generate data
  • 44. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins freezegun and then check it
  • 45. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-eradicate Plugin that detect if we left commented code. Is able to differentiate commented code from real comments. Before executing pytest --eradicate
  • 46. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-eradicate Plugin that detect if we left commented code. Is able to differentiate commented code from real comments. After executing pytest --eradicate
  • 47. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-eradicate Plugin that detect if we left commented code. Is able to differentiate commented code from real comments.
  • 48. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-xdist Plugin that allows us to run tests in parallel, allows us to reduce the total execution time. It is mandatory that the tests are completely self-contained for the use of xdist. When tests are invoked with xdist, pytest-django will create a separate test database for each process. Each test database will be given a suffix (something like “gw0”, “gw1”) to map to a xdist process.
  • 49. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-xdist
  • 50. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-xdist
  • 51. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins Package that helps us generate data random for our specification or data model. Helps us to test that our code works for any value within a range and not only for specific cases. hypothesis
  • 52. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins hypothesis
  • 53. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins hypothesis
  • 54. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-watch It helps us to re-launch, automatically, the tests when changes have been detected in the project files Allows us to execute commands before and after the execution of the tests and also commands depending on the success or failure of the tests We use it in combination with the following plugin, pytest-testmon
  • 55. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-testmon Select and re-execute only the tests affected by the latest changes, whether they are changes in business classes or in the tests themselves https://www.youtube.com/watch?v=1xahPJ_LNXM&feature=youtu.be
  • 56. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-testmon Select and re-execute only the tests affected by the latest changes, whether they are changes in business classes or in the tests themselves
  • 57. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-splinter Plugin that allow us to execute browser session for the execution of functional tests It gives us a bunch of fixtures Allow to capture the screen when an error has ocurred It allows us to execute the tests on remote servers (e.g.: sauce labs)
  • 58. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-splinter Allows the execution of javascript inside the test itself
  • 59. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-splinter Test example
  • 60. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Plugins pytest-splinter Test example
  • 61. Andreu Vallbona - PyBCN - June 2019Pytest: recommendations and basic packages for testing in Python and Django Thanks That’s all. Thank you! Questions? @avallbona