SlideShare a Scribd company logo
simple is better than complex
The Zen of Python (import this)
Qualidade levada a sério em Python
• Master Coaching Trainer
• Pesquisador de segurança sênior
• Programador C/C++ e Python
• Data Scientist
• Viciado em competições de ML
• Coordenador equipe ameaças PSafe
5° software mais baixado
Maior empresa mobile LA
200 mil downloads/dia
Qualidade levada a sério em Python - Emilio Simoni
Pessoas
Processo
Produto
Versionamento
Qualidade
Automatização
Requisitos
Metodologia
Processo = Engenharia de software
Testes
Analise estática
Bug Tracking
Documentação
Qualidade levada a sério em Python - Emilio Simoni
Qualidade levada a sério em Python - Emilio Simoni
Qualidade levada a sério em Python - Emilio Simoni
Testes de
software
Qualidade levada a sério em Python - Emilio Simoni
Qualidade levada a sério em Python - Emilio Simoni
Qualidade levada a sério em Python - Emilio Simoni
Específicos
Auto descritivos
Auto suficientes
Indicar o comportamento esperado
Servir de documentação
Bugs tendem a virar um caso de teste
Unit Tests
PyUnit
Unit Tests
assertTrue
assertEqual
assertAlmostEqual
assertIn
Mão na massa!
Test Fixture
Test Case
Test Suite
Test Runner
Unit Tests
Test Fixture
Test Fixture
class SimpleTestCase(unittest.TestCase):
def setUp(self):
"""Call before every test case.""“
self.foo = Foo()
self.file = open( "blah", "r" )
def tearDown(self):
"""Call after every test case.""“
self.file.close()
OQueTaSendoTestando_Parametros_RetornoEsperado
get_client_name__with_invalid__params_must_return_False
Test Case
def test_get_client_name__with_invalid__params_must_return_False (self):
"""Test case 1. note that all test method names must begin with 'test.'""“
self.assertEqual(foo.get_client_name(None) , False)
OQueTaSendoTestando_Parametros_RetornoEsperado
get_client_name__with_invalid__params_must_return_False
import unittest
from foobarbaz import Foo # code from module you're testing
class SimpleTestCase(unittest.TestCase):
def setUp(self):
"""Call before every test case.""“
self.foo = Foo()
self.file = open( "blah", "r" )
def tearDown(self):
"""Call after every test case.""“
self.file.close()
def test_get_client_name__with_invalid__params_must_return_False (self):
"""Test case 1. note that all test method names must begin with 'test.'""“
self.assertEqual(foo.get_client_name(None) , False)
Test Suite
Gerencia os testes e fornece uma interface de acesso.
Test Runner
Qualidade levada a sério em Python - Emilio Simoni
Teste se torna o primeiro cliente do seu código
Somente o codigo necessario é criado
Erros são identificados mais rapidamente
Ganho de produtividade
Códigos entregues realmente prontos
Facilita depuração
Integration Tests
Integration Tests
def test_add_source_must_check_duplicated(self):
psw = PhishingServiceWrapper()
psw.add_url('http://www.testededominio.com.br', source_id=1)
add_ret = psw.add_url('http://www.testededominio.com.br', source_id=1)
self.assertEqual(add_ret['status'], 'duplicated')
Performance Tests
Performance Tests
__main__.SomeTest.testOne: 1.001
__main__.SomeTest.testTwo: 2.002
-----------------------------------------------
Ran 2 tests in 3.003s OK
Performance Tests
import cProfile
import unittest
if __name__ == '__main__':
suite = unittest.TestLoader().discover('.')
def runtests():
unittest.TextTestRunner().run(suite)
cProfile.run('runtests()',sort='cumtime')
Performance Tests
25510 function calls (25298 primitive calls) in 0.820 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.820 0.820 <string>:1(<module>)
Performance Tests
def test_add_source_must_check_duplicated(self):
import time
psw = PhishingServiceWrapper()
before_functiion = time.time()
psw.add_url('http://www.testededominio.com.br', source_id=1)
after_functiion = time.time()
self.assertLess(after_functiion - before_function, 1.0)
Performance Tests@profile
def primes(n):
if n==2:
return [2]
elif n<2:
return []
s=range(3,n+1,2)
mroot = n ** 0.5
half=(n+1)/2-1
i=0
m=3
while m <= mroot:
if s[i]:
j=(m*m-3)/2
s[j]=0
while j<half:
s[j]=0
j+=m
i=i+1
m=2*i+3
return [2]+[x for x in s if x]
primes(100)
pip install line_profiler
kernprof -l –v primes.py
Performance Tests
Line # Hits Time Per Hit % Time Line Contents
==============================================================
2 @profile
3 def primes(n):
4 1 2 2.0 1.1 if n==2:
5 return [2]
6 1 1 1.0 0.5 elif n<2:
7 return []
8 1 4 4.0 2.1 s=range(3,n+1,2)
9 1 10 10.0 5.3 mroot = n ** 0.5
10 1 2 2.0 1.1 half=(n+1)/2-1
11 1 1 1.0 0.5 i=0
12 1 1 1.0 0.5 m=3
13 5 7 1.4 3.7 while m <= mroot:
14 4 4 1.0 2.1 if s[i]:
15 3 4 1.3 2.1 j=(m*m-3)/2
16 3 4 1.3 2.1 s[j]=0
17 31 31 1.0 16.3 while j<half:
18 28 28 1.0 14.7 s[j]=0
19 28 29 1.0 15.3 j+=m
20 4 4 1.0 2.1 i=i+1
21 4 4 1.0 2.1 m=2*i+3
22 50 54 1.1 28.4 return [2]+[x for x in s if x]
Performance Tests
python -m memory_profiler primes.py
pip install memory_profiler
Performance
2 @profile
3 7.9219 MB 0.0000 MB def primes(n):
4 7.9219 MB 0.0000 MB if n==2:
5 return [2]
6 7.9219 MB 0.0000 MB elif n<2:
7 return []
8 7.9219 MB 0.0000 MB s=range(3,n+1,2)
9 7.9258 MB 0.0039 MB mroot = n ** 0.5
10 7.9258 MB 0.0000 MB half=(n+1)/2-1
11 7.9258 MB 0.0000 MB i=0
12 7.9258 MB 0.0000 MB m=3
13 7.9297 MB 0.0039 MB while m <= mroot:
14 7.9297 MB 0.0000 MB if s[i]:
15 7.9297 MB 0.0000 MB j=(m*m-3)/2
16 7.9258 MB -0.0039 MB s[j]=0
17 7.9297 MB 0.0039 MB while j<half:
18 7.9297 MB 0.0000 MB s[j]=0
19 7.9297 MB 0.0000 MB j+=m
20 7.9297 MB 0.0000 MB i=i+1
21 7.9297 MB 0.0000 MB m=2*i+3
22 7.9297 MB 0.0000 MB return [2]+[x for x in s if x]
Bug Tracking
Bug Tracking
import unittest
from foobarbaz import Foo
class SimpleTestCase(unittest.TestCase):
def setUp(self):
"""Call before every test case.""“
self.foo = Foo()
self.file = open( "blah", "r" )
def tearDown(self):
"""Call after every test case.""“
self.file.close()
def test_get_client_name__with_big_param__must_return_False (self):
self.assertEqual(foo.get_client_name(“A” * 1024*1024) , False)
Analise estática
Analise estática
Checar idioma
Documentação de codigo
Compliance
Erros
Codigos duplicados ou complexos
pylint file.py
pip install pylint
Analise estática
Analise estática
radon
pip install radon
Complexidade ciclomática
Linhas de código, comentários, ...
Maintainability Index
Analise estática
Analise estática
Analise estática
Analise estática
Documentação
DocStrings
Documentação simples e clara, não deve conter detalhes da implementação
Documentação ruim é pior do que não documentado
Sumarizar o comportamento da função
Argumentos, retornos, exceções disparadas e restrições.
Não documentar o obvio
Documentação
import this
simple is better than complex
pep-0020
The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
emiliocini@gmail.com
www.emiliosimoni.com

More Related Content

PDF
Python testing using mock and pytest
PDF
Test Driven Development With Python
PDF
Node.js flow control
PPT
Python testing
PPT
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
PDF
Обзор фреймворка Twisted
PDF
Pytest: escreva menos, teste mais
PDF
JavaOne 2015 - Having fun with Javassist
Python testing using mock and pytest
Test Driven Development With Python
Node.js flow control
Python testing
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Обзор фреймворка Twisted
Pytest: escreva menos, teste mais
JavaOne 2015 - Having fun with Javassist

What's hot (20)

KEY
Django’s nasal passage
PDF
Operating System Lab Manual
PPTX
Дмитрий Демчук. Кроссплатформенный краш-репорт
PDF
Spock: A Highly Logical Way To Test
PPTX
Introducing to Asynchronous Programming
PDF
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
ODP
Intro to Testing in Zope, Plone
PDF
Python meetup: coroutines, event loops, and non-blocking I/O
PDF
GenServer in action
PDF
Python Coroutines, Present and Future
PDF
Riga Dev Day 2016 - Having fun with Javassist
PDF
Effective testing with pytest
DOCX
Assignment no39
PPT
Introduzione al TDD
PDF
생산적인 개발을 위한 지속적인 테스트
PDF
Oredev 2015 - Taming Java Agents
PPT
Phpunit testing
PDF
Pytest - testing tips and useful plugins
KEY
Gevent what's the point
Django’s nasal passage
Operating System Lab Manual
Дмитрий Демчук. Кроссплатформенный краш-репорт
Spock: A Highly Logical Way To Test
Introducing to Asynchronous Programming
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Intro to Testing in Zope, Plone
Python meetup: coroutines, event loops, and non-blocking I/O
GenServer in action
Python Coroutines, Present and Future
Riga Dev Day 2016 - Having fun with Javassist
Effective testing with pytest
Assignment no39
Introduzione al TDD
생산적인 개발을 위한 지속적인 테스트
Oredev 2015 - Taming Java Agents
Phpunit testing
Pytest - testing tips and useful plugins
Gevent what's the point
Ad

Viewers also liked (15)

PPT
Prototype Framework Javascript
PDF
Maio 2016 - O QA em um Time Ágil
PDF
Dezembro 2015 - UI AutoMonkey - Teste Automatizado iOS
PPTX
Março 2016 - Como testar sua API Rest
PDF
Junho 2016 - Testes de Carga com Locust
PDF
Testes em um contexto de Continuous Delivery
PDF
Maio 2016 - Integração e Validação Contínua
PPTX
Testes de integração automatizados com GoCD e Consu
PPTX
Cloud Computing e Integração Contínua com o Windows Azure
PDF
Dezembro 2015 - Primeiros Passos em Automação de Testes
PDF
Charles Proxy, um canivete suíço para o dia a dia de desenvolvimento (testes)
PPTX
Automação de Testes de Aceitação em Sistemas Web
PPTX
Julho 2016 - Microsoft Test Manager
PDF
Junho 2016 - Django - A sua cápsula de soluções web em python
PPTX
Teste de segurança em aplicações web ( sites )
Prototype Framework Javascript
Maio 2016 - O QA em um Time Ágil
Dezembro 2015 - UI AutoMonkey - Teste Automatizado iOS
Março 2016 - Como testar sua API Rest
Junho 2016 - Testes de Carga com Locust
Testes em um contexto de Continuous Delivery
Maio 2016 - Integração e Validação Contínua
Testes de integração automatizados com GoCD e Consu
Cloud Computing e Integração Contínua com o Windows Azure
Dezembro 2015 - Primeiros Passos em Automação de Testes
Charles Proxy, um canivete suíço para o dia a dia de desenvolvimento (testes)
Automação de Testes de Aceitação em Sistemas Web
Julho 2016 - Microsoft Test Manager
Junho 2016 - Django - A sua cápsula de soluções web em python
Teste de segurança em aplicações web ( sites )
Ad

Similar to Qualidade levada a sério em Python - Emilio Simoni (20)

KEY
Testing My Patience
PDF
Unit test
PDF
Python Unit Test
PDF
Your Last manual Assessment
PDF
Django (Web Konferencia 2009)
ODP
Pruebas unitarias con django
PDF
Тестирование и Django
PDF
Py.test
PPTX
Python 표준 라이브러리
PDF
How to fake_properly
PDF
Запускаем тесты в Continuous Integration - Сергей Пак (JetBrains)
ODP
Grails unit testing
PDF
Python profiling
PPTX
Automated Python Test Frameworks for Hardware Verification and Validation
PDF
Make Sure Your Applications Crash
PDF
Testing for Pragmatic People
PDF
Spock and Geb in Action
KEY
Python Development (MongoSF)
PDF
2011 py con
PDF
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
Testing My Patience
Unit test
Python Unit Test
Your Last manual Assessment
Django (Web Konferencia 2009)
Pruebas unitarias con django
Тестирование и Django
Py.test
Python 표준 라이브러리
How to fake_properly
Запускаем тесты в Continuous Integration - Сергей Пак (JetBrains)
Grails unit testing
Python profiling
Automated Python Test Frameworks for Hardware Verification and Validation
Make Sure Your Applications Crash
Testing for Pragmatic People
Spock and Geb in Action
Python Development (MongoSF)
2011 py con
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb

Recently uploaded (20)

PPTX
GSA Content Generator Crack (2025 Latest)
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
CNN LeNet5 Architecture: Neural Networks
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PPTX
Patient Appointment Booking in Odoo with online payment
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Types of Token_ From Utility to Security.pdf
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
Cost to Outsource Software Development in 2025
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
GSA Content Generator Crack (2025 Latest)
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
CNN LeNet5 Architecture: Neural Networks
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
Patient Appointment Booking in Odoo with online payment
Advanced SystemCare Ultimate Crack + Portable (2025)
Computer Software and OS of computer science of grade 11.pptx
Types of Token_ From Utility to Security.pdf
Monitoring Stack: Grafana, Loki & Promtail
DNT Brochure 2025 – ISV Solutions @ D365
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Autodesk AutoCAD Crack Free Download 2025
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Why Generative AI is the Future of Content, Code & Creativity?
How to Use SharePoint as an ISO-Compliant Document Management System
Trending Python Topics for Data Visualization in 2025
Cost to Outsource Software Development in 2025
Visual explanation of Dijkstra's Algorithm using Python
Top 10 Software Development Trends to Watch in 2025 🚀.pdf

Qualidade levada a sério em Python - Emilio Simoni