SlideShare a Scribd company logo
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

More Related Content

What's hot

Python unit testing
Python unit testingPython unit testing
Python unit testing
Darryl Sherman
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Scott Leberknight
 
05 junit
05 junit05 junit
05 junit
mha4
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test PresentationSayedur Rahman
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
KadarkaraiSelvam
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
Maayan Glikser
 
TestNG
TestNGTestNG
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
Suraj Deshmukh
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
David Berliner
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
Nayanda Haberty
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
ikhwanhayat
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
MicroPyramid .
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
Narendran Solai Sridharan
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
Lilia Sfaxi
 

What's hot (20)

Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
05 junit
05 junit05 junit
05 junit
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
Unit testing with java
Unit testing with javaUnit testing with java
Unit testing with java
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
TestNG
TestNGTestNG
TestNG
 
Hybrid framework
Hybrid frameworkHybrid framework
Hybrid framework
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
Mockito
MockitoMockito
Mockito
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 

Viewers also liked

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
Adriano 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 Django
fabiocerqueira
 
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 Mommy
Bernardo 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 factoryboy
Leonardo Galani
 
Customizando Admin do Django
Customizando Admin do DjangoCustomizando Admin do Django
Customizando Admin do Django
Gustavo 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 mitologicos
Adriano 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
 
REST com Python
REST com PythonREST com Python
REST com Python
fabiocerqueira
 
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
Priscila 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 Python
Rodrigo 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 web2py
Gilson 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 Python
Giancarlo Silva
 
Python - Programação funcional
Python - Programação funcionalPython - Programação funcional
Python - Programação funcional
fabiocerqueira
 
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
 

Viewers also liked (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
 

Similar to Testes pythonicos com pytest

Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
Eric 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] 2023
Mark 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 Python
Siddhi
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in python
Jimmy Lai
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
Yeongseon Choe
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
André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 Deployment
Mark 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 Projects
Clayton Parker
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010Timo Stollenwerk
 
Auto testing!
Auto testing!Auto testing!
Auto testing!
Kwangsoo Shin
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
Rainer Schuettengruber
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
Eric Hogue
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
Adam Lowry
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
Ray Toal
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
MoscowDjango
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packagesQuintagroup
 

Similar to 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
 

More from viniciusban

Gitlab flow solo
Gitlab flow soloGitlab flow solo
Gitlab flow solo
viniciusban
 
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
 
Gitlab flow
Gitlab flowGitlab flow
Gitlab flow
viniciusban
 
Git na pratica
Git na praticaGit na pratica
Git na pratica
viniciusban
 
Git conceitos
Git conceitosGit conceitos
Git conceitos
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
 

More from 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ê?
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

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