SlideShare uma empresa Scribd logo
1 de 13
1 de 13
py.test
testes
pythonicos
com
Vinicius Assef - @viniciusban
2 de 13
ambiente
● sem boilerplate
● sem classes
● roda doctests, unittests e nosetests
$ pip install pytest
3 de 13
# test_f.py
from modulo import f
def test_f():
assert f(1) == 1
simplesmente teste
# test_f.py
import pytest
from modulo import um
def test_um():
with pytest.raises(ValueError):
um(2)
4 de 13
convenções
● test_*.py ou *_test.py
● recursedirs
● class Test* # sem def __init__()
● def test_*()
● configuráveis via .ini
5 de 13
mensagens de erro
$ pytest -v
======================== test session starts
=========================
platform linux2 -- Python 2.7.3 -- pytest-2.3.5
collected 1 items
test_f.py:10: test_f1_eh_1 FAILED
============================== FAILURES
==============================
____________________________ test_f1_eh_1
____________________________
def test_f1_eh_1():
> assert f(1) == 0
E assert 1 == 0
E + where 1 = f(1)
test_f.py:11: AssertionError
====================== 1 failed in 0.01 seconds
======================
6 de 13
erro em lista
============================== FAILURES
==============================
________________________ test_lista_completa
_________________________
def test_lista_completa():
> assert "a b".split() == lista()
E assert ['a', 'b'] == ['a', 'b', 'c']
E Right contains more items, first extra item: 'c'
test_f.py:8: AssertionError
====================== 1 failed in 0.01 seconds
======================
7 de 13
erro em dicionário
__________________________ test_dicionario
___________________________
def test_dicionario():
> assert dict(i=20, n="pedro", f="junior") == dicionario()
E assert {'f': 'junior... 'n': 'pedro'} == {'i': 20, 'n':
'pedro'}
E Hiding 2 identical items, use -v to show
E Left contains more items:
E {'f': 'junior'}
test_f.py:10: AssertionError
================= 1 failed, 1 passed in 0.02 seconds
=================
8 de 13
# conftest.py
import pytest
@pytest.fixture
def texto():
return "abc"
fixtures
# test_tudo.py
def test_abc(texto):
assert texto == "abc"
9 de 13
# conftest.py
import pytest
@pytest.fixture
def xyz():
return "x"
@pytest.fixture
def texto(xyz):
return "abc %s" % xyz
fixtures consomem fixtures
10 de 13
escopo de fixtures
@pytest.fixture(scope="module")
● setUp e tearDown
● request.addfinalizer()
● podem receber parâmetros do módulo de
teste
11 de 13
fixtures automáticas
@pytest.fixture(autouse=True)
● setUp e tearDown on steroids
12 de 13
plugins
● pytest-django
● pytest-xdist
● pytest-pep8
● pytest-cov
● oejskit
● Executados automaticamente
13 de 13
viniciusban
twitter
gmail
github
skype

Mais conteúdo relacionado

Mais procurados

Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Data Driven Framework in Selenium
Data Driven Framework in SeleniumData Driven Framework in Selenium
Data Driven Framework in SeleniumKnoldus Inc.
 
Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Ippon
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDSCVSSUT
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingJoe Tremblay
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PBAbhishek Yadav
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
O que há de incrível sobre o Flutter
O que há de incrível sobre o FlutterO que há de incrível sobre o Flutter
O que há de incrível sobre o FlutterWiliam Buzatto
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 

Mais procurados (20)

Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Data Driven Framework in Selenium
Data Driven Framework in SeleniumData Driven Framework in Selenium
Data Driven Framework in Selenium
 
Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Scripting robot
Scripting robotScripting robot
Scripting robot
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptx
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
testng
testngtestng
testng
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Junit
JunitJunit
Junit
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
Google test training
Google test trainingGoogle test training
Google test training
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
O que há de incrível sobre o Flutter
O que há de incrível sobre o FlutterO que há de incrível sobre o Flutter
O que há de incrível sobre o Flutter
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 

Destaque

TDD em django sem desculpas versao fisl
TDD em django sem desculpas versao fislTDD em django sem desculpas versao fisl
TDD em django sem desculpas versao fislAdriano Petrich
 
Testes, deploy e integração continua com Python e Django
Testes, deploy e integração continua com Python e DjangoTestes, deploy e integração continua com Python e Django
Testes, deploy e integração continua com Python e Djangofabiocerqueira
 
Testando Aplicações Django: Quando, Como e Onde?
Testando Aplicações Django: Quando, Como e Onde?Testando Aplicações Django: Quando, Como e Onde?
Testando Aplicações Django: Quando, Como e Onde?Bernardo Fontes
 
Melhorando Testes No Django Com O Model Mommy
Melhorando Testes No Django Com O Model MommyMelhorando Testes No Django Com O Model Mommy
Melhorando Testes No Django Com O Model MommyBernardo Fontes
 
Como melhoramos a performance dos testes automatizados com py.test e factoryboy
Como melhoramos a performance dos testes automatizados com py.test e factoryboyComo melhoramos a performance dos testes automatizados com py.test e factoryboy
Como melhoramos a performance dos testes automatizados com py.test e factoryboyLeonardo Galani
 
Customizando Admin do Django
Customizando Admin do DjangoCustomizando Admin do Django
Customizando Admin do DjangoGustavo Carvalho
 
python: Listas, deques, Dicionarios e outros monstros mitologicos
python: Listas, deques, Dicionarios e outros monstros mitologicospython: Listas, deques, Dicionarios e outros monstros mitologicos
python: Listas, deques, Dicionarios e outros monstros mitologicosAdriano Petrich
 
Django: um framework web para perfeccionistas com prazo
Django: um framework web para perfeccionistas com prazoDjango: um framework web para perfeccionistas com prazo
Django: um framework web para perfeccionistas com prazoBernardo Fontes
 
Aula 5 linguagens regularese automatosfinitosnãodeterministico
Aula 5   linguagens regularese automatosfinitosnãodeterministicoAula 5   linguagens regularese automatosfinitosnãodeterministico
Aula 5 linguagens regularese automatosfinitosnãodeterministicowab030
 
Apresentando a Linguagem de Programação Python
Apresentando a Linguagem de Programação PythonApresentando a Linguagem de Programação Python
Apresentando a Linguagem de Programação PythonPriscila Mayumi
 
Arduino: Brincando de eletrônica com Python e Hardware Livre
Arduino: Brincando de eletrônica com Python e Hardware LivreArduino: Brincando de eletrônica com Python e Hardware Livre
Arduino: Brincando de eletrônica com Python e Hardware LivreÁlvaro Justen
 
Apresentação python fábio jr alves
Apresentação python   fábio jr alvesApresentação python   fábio jr alves
Apresentação python fábio jr alvesGrupython Ufla
 
14 programando em python - interfaces graficas com tk
 14   programando em python - interfaces graficas com tk 14   programando em python - interfaces graficas com tk
14 programando em python - interfaces graficas com tkVictor Marcelino
 
Introdução à Programação em Python
Introdução à Programação em PythonIntrodução à Programação em Python
Introdução à Programação em PythonRodrigo Hübner
 
Desenvolvendo aplicações web com python e web2py
Desenvolvendo aplicações web com python e web2pyDesenvolvendo aplicações web com python e web2py
Desenvolvendo aplicações web com python e web2pyGilson Filho
 
Seminário - Guido van Rossum: Breve história da linguagem Python
Seminário - Guido van Rossum: Breve história da linguagem PythonSeminário - Guido van Rossum: Breve história da linguagem Python
Seminário - Guido van Rossum: Breve história da linguagem PythonGiancarlo Silva
 
Python - Programação funcional
Python - Programação funcionalPython - Programação funcional
Python - Programação funcionalfabiocerqueira
 
Arduino: Robótica e Automação com Software e Hardware Livres
Arduino: Robótica e Automação com Software e Hardware LivresArduino: Robótica e Automação com Software e Hardware Livres
Arduino: Robótica e Automação com Software e Hardware LivresÁlvaro Justen
 

Destaque (20)

TDD em django sem desculpas versao fisl
TDD em django sem desculpas versao fislTDD em django sem desculpas versao fisl
TDD em django sem desculpas versao fisl
 
Testes, deploy e integração continua com Python e Django
Testes, deploy e integração continua com Python e DjangoTestes, deploy e integração continua com Python e Django
Testes, deploy e integração continua com Python e Django
 
Testando Aplicações Django: Quando, Como e Onde?
Testando Aplicações Django: Quando, Como e Onde?Testando Aplicações Django: Quando, Como e Onde?
Testando Aplicações Django: Quando, Como e Onde?
 
TDD com Python
TDD com PythonTDD com Python
TDD com Python
 
Melhorando Testes No Django Com O Model Mommy
Melhorando Testes No Django Com O Model MommyMelhorando Testes No Django Com O Model Mommy
Melhorando Testes No Django Com O Model Mommy
 
Como melhoramos a performance dos testes automatizados com py.test e factoryboy
Como melhoramos a performance dos testes automatizados com py.test e factoryboyComo melhoramos a performance dos testes automatizados com py.test e factoryboy
Como melhoramos a performance dos testes automatizados com py.test e factoryboy
 
Customizando Admin do Django
Customizando Admin do DjangoCustomizando Admin do Django
Customizando Admin do Django
 
python: Listas, deques, Dicionarios e outros monstros mitologicos
python: Listas, deques, Dicionarios e outros monstros mitologicospython: Listas, deques, Dicionarios e outros monstros mitologicos
python: Listas, deques, Dicionarios e outros monstros mitologicos
 
Django: um framework web para perfeccionistas com prazo
Django: um framework web para perfeccionistas com prazoDjango: um framework web para perfeccionistas com prazo
Django: um framework web para perfeccionistas com prazo
 
Aula 5 linguagens regularese automatosfinitosnãodeterministico
Aula 5   linguagens regularese automatosfinitosnãodeterministicoAula 5   linguagens regularese automatosfinitosnãodeterministico
Aula 5 linguagens regularese automatosfinitosnãodeterministico
 
REST com Python
REST com PythonREST com Python
REST com Python
 
Apresentando a Linguagem de Programação Python
Apresentando a Linguagem de Programação PythonApresentando a Linguagem de Programação Python
Apresentando a Linguagem de Programação Python
 
Arduino: Brincando de eletrônica com Python e Hardware Livre
Arduino: Brincando de eletrônica com Python e Hardware LivreArduino: Brincando de eletrônica com Python e Hardware Livre
Arduino: Brincando de eletrônica com Python e Hardware Livre
 
Apresentação python fábio jr alves
Apresentação python   fábio jr alvesApresentação python   fábio jr alves
Apresentação python fábio jr alves
 
14 programando em python - interfaces graficas com tk
 14   programando em python - interfaces graficas com tk 14   programando em python - interfaces graficas com tk
14 programando em python - interfaces graficas com tk
 
Introdução à Programação em Python
Introdução à Programação em PythonIntrodução à Programação em Python
Introdução à Programação em Python
 
Desenvolvendo aplicações web com python e web2py
Desenvolvendo aplicações web com python e web2pyDesenvolvendo aplicações web com python e web2py
Desenvolvendo aplicações web com python e web2py
 
Seminário - Guido van Rossum: Breve história da linguagem Python
Seminário - Guido van Rossum: Breve história da linguagem PythonSeminário - Guido van Rossum: Breve história da linguagem Python
Seminário - Guido van Rossum: Breve história da linguagem Python
 
Python - Programação funcional
Python - Programação funcionalPython - Programação funcional
Python - Programação funcional
 
Arduino: Robótica e Automação com Software e Hardware Livres
Arduino: Robótica e Automação com Software e Hardware LivresArduino: Robótica e Automação com Software e Hardware Livres
Arduino: Robótica e Automação com Software e Hardware Livres
 

Semelhante a Testes pythonicos com pytest

Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDDEric Hogue
 
Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Mark Niebergall
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...Rodolfo Carvalho
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With PythonSiddhi
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in pythonJimmy Lai
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기Yeongseon Choe
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in pythonAndrés J. Díaz
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentMark Niebergall
 
Using Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsUsing Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsClayton Parker
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010Timo Stollenwerk
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Eric Hogue
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My PatienceAdam Lowry
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutesRay Toal
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, PloneQuintagroup
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и DjangoMoscowDjango
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packagesQuintagroup
 

Semelhante a Testes pythonicos com pytest (20)

UPC Testing talk 2
UPC Testing talk 2UPC Testing talk 2
UPC Testing talk 2
 
Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
 
Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in python
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
 
Python testing
Python  testingPython  testing
Python testing
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
Using Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python ProjectsUsing Buildout to Develop and Deploy Python Projects
Using Buildout to Develop and Deploy Python Projects
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010
 
Auto testing!
Auto testing!Auto testing!
Auto testing!
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packages
 

Mais de viniciusban

Gitlab flow solo
Gitlab flow soloGitlab flow solo
Gitlab flow soloviniciusban
 
Gitlab flow solo (pt-BR)
Gitlab flow solo (pt-BR)Gitlab flow solo (pt-BR)
Gitlab flow solo (pt-BR)viniciusban
 
Gitlab flow solo (minimo)
Gitlab flow solo (minimo)Gitlab flow solo (minimo)
Gitlab flow solo (minimo)viniciusban
 
Git commits - como, quando e por quê?
Git commits - como, quando e por quê?Git commits - como, quando e por quê?
Git commits - como, quando e por quê?viniciusban
 

Mais de viniciusban (7)

Gitlab flow solo
Gitlab flow soloGitlab flow solo
Gitlab flow solo
 
Gitlab flow solo (pt-BR)
Gitlab flow solo (pt-BR)Gitlab flow solo (pt-BR)
Gitlab flow solo (pt-BR)
 
Gitlab flow solo (minimo)
Gitlab flow solo (minimo)Gitlab flow solo (minimo)
Gitlab flow solo (minimo)
 
Gitlab flow
Gitlab flowGitlab flow
Gitlab flow
 
Git na pratica
Git na praticaGit na pratica
Git na pratica
 
Git conceitos
Git conceitosGit conceitos
Git conceitos
 
Git commits - como, quando e por quê?
Git commits - como, quando e por quê?Git commits - como, quando e por quê?
Git commits - como, quando e por quê?
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Testes pythonicos com pytest

  • 2. 2 de 13 ambiente ● sem boilerplate ● sem classes ● roda doctests, unittests e nosetests $ pip install pytest
  • 3. 3 de 13 # test_f.py from modulo import f def test_f(): assert f(1) == 1 simplesmente teste # test_f.py import pytest from modulo import um def test_um(): with pytest.raises(ValueError): um(2)
  • 4. 4 de 13 convenções ● test_*.py ou *_test.py ● recursedirs ● class Test* # sem def __init__() ● def test_*() ● configuráveis via .ini
  • 5. 5 de 13 mensagens de erro $ pytest -v ======================== test session starts ========================= platform linux2 -- Python 2.7.3 -- pytest-2.3.5 collected 1 items test_f.py:10: test_f1_eh_1 FAILED ============================== FAILURES ============================== ____________________________ test_f1_eh_1 ____________________________ def test_f1_eh_1(): > assert f(1) == 0 E assert 1 == 0 E + where 1 = f(1) test_f.py:11: AssertionError ====================== 1 failed in 0.01 seconds ======================
  • 6. 6 de 13 erro em lista ============================== FAILURES ============================== ________________________ test_lista_completa _________________________ def test_lista_completa(): > assert "a b".split() == lista() E assert ['a', 'b'] == ['a', 'b', 'c'] E Right contains more items, first extra item: 'c' test_f.py:8: AssertionError ====================== 1 failed in 0.01 seconds ======================
  • 7. 7 de 13 erro em dicionário __________________________ test_dicionario ___________________________ def test_dicionario(): > assert dict(i=20, n="pedro", f="junior") == dicionario() E assert {'f': 'junior... 'n': 'pedro'} == {'i': 20, 'n': 'pedro'} E Hiding 2 identical items, use -v to show E Left contains more items: E {'f': 'junior'} test_f.py:10: AssertionError ================= 1 failed, 1 passed in 0.02 seconds =================
  • 8. 8 de 13 # conftest.py import pytest @pytest.fixture def texto(): return "abc" fixtures # test_tudo.py def test_abc(texto): assert texto == "abc"
  • 9. 9 de 13 # conftest.py import pytest @pytest.fixture def xyz(): return "x" @pytest.fixture def texto(xyz): return "abc %s" % xyz fixtures consomem fixtures
  • 10. 10 de 13 escopo de fixtures @pytest.fixture(scope="module") ● setUp e tearDown ● request.addfinalizer() ● podem receber parâmetros do módulo de teste
  • 11. 11 de 13 fixtures automáticas @pytest.fixture(autouse=True) ● setUp e tearDown on steroids
  • 12. 12 de 13 plugins ● pytest-django ● pytest-xdist ● pytest-pep8 ● pytest-cov ● oejskit ● Executados automaticamente