SlideShare a Scribd company logo
What is doctest?
Python testing frameworks overview
1 / 26
What am I doing here?
2 / 26
What am I doing here?
Facts
Jachym Cepicky
GIS (maps in computer)
Open source software
Not facts
not a tester
not educated software engineer
nor GIS educated
3 / 26
What am I doing here?
Me: confused py.test with doctest
4 / 26
Let's get started
5 / 26
Testing motivation
6 / 26
Everybody loves to tests.
7 / 26
Everybody has heard, that using TDD is the only way how to write
code loves to tests.
8 / 26
TDD
9 / 26
The fact
Writing tests
...
does make sense
10 / 26
Summary
Making sure, that the system
meets the requirements that guided its design and development,
responds correctly to all kinds of inputs,
performs its functions within an acceptable time,
is sufficiently usable,
can be installed and run in its intended environments, and
achieves the general result its stakeholders desire.
https://en.wikipedia.org/wiki/Software_testing
11 / 26
Testing in Python - overview
12 / 26
It's pretty cool and easy to test in Python
13 / 26
Unittest
https://docs.python.org/3/library/unittest.html
originally inspired by JUnit (inspired by SUnit for Smalltalk, since 1998)
https://shebanator.com/2007/08/21/a-brief-history-of-test-frameworks/
Pros
Native framework
Testing methods
Supported everywhere
Auto discovery of test classes and functions
Cons
Classes
Testing methods
Complicated (for some people)
Lack of Group fixtures (specified environment for a whole group)
Still better to separate testing code from business logic
Unit-test oriented
14 / 26
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
15 / 26
$ python my_unittest.py
.F.
======================================================================
FAIL: test_split (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "neco.py", line 14, in test_split
self.assertEqual(s.split(), ['hellox', 'world'])
AssertionError: Lists differ: ['hello', 'world'] != ['hellox', 'world']
First differing element 0:
'hello'
'hellox'
- ['hello', 'world']
+ ['hellox', 'world']
? +
----------------------------------------------------------------------
Ran 3 tests in 0.001s
FAILED (failures=1)
16 / 26
py.test
http://doc.pytest.org/en/latest/
Pros
Plugins
HTML output
Simpler and more straight-forward syntax
Auto discovery of test functions
Distributed
Cons
Not native
Can get complicated too (decorators)
17 / 26
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
18 / 26
$ python3 -m pytest my_pytest.py
============================================ test session starts ============================================
platform linux -- Python 3.5.2+, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /tmp, inifile:
collected 2 items
neco.py F.
================================================= FAILURES ==================================================
________________________________________________ test_answer ________________________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
neco.py:5: AssertionError
==================================== 1 failed, 1 passed in 0.03 seconds =====================================
19 / 26
Doctest
https://docs.python.org/3/library/doctest.html
Pros
Native
Tests are (can be) part of class and method documentation
Can be in separated text (e.g. README) files
Supported by Sphinx
Cons
Not suitable for larger testing systems
No fixtures
20 / 26
def unique_words(page):
''' Returns set of the unique words in list of lines of text
Example:
>>> from StringIO import StringIO
>>> fileText = """the cat sat on the mat
... the mat was ondur the cat
... one fish two fish red fish
... blue fish
... This fish has a yellow car
... This fish has a yellow star"""
>>> file = StringIO(fileText)
>>> page = file.readlines()
>>> words = unique_words(page)
>>> print sorted(list(words))
["This", "a", "blue", "car", "cat", "fish", "has", "mat",
"on", "ondur", "one", "red", "sat", "star", "the", "two",
"was", "yellow"]
>>>
'''
return set(word for line in page for word in line.split())
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
21 / 26
$ python2 my_doctest.py
**********************************************************************
File "neco.py", line 16, in __main__.unique_words
Failed example:
print sorted(list(words))
Expected:
["This", "a", "blue", "car", "cat", "fish", "has", "mat",
"on", "ondur", "one", "red", "sat", "star", "the", "two",
"was", "yellow"]
Got:
['This', 'a', 'blue', 'car', 'cat', 'fish', 'has', 'mat', 'on', 'ondur', 'one', 'red', 'sat', 'star', 'the', 'two', 'was', 'yellow']
**********************************************************************
1 items had failures:
1 of 6 in __main__.unique_words
***Test Failed*** 1 failures.
22 / 26
nose (nose2)
nose extends unittest to make testing easier
smart developer should get familiar doctest, unittest, pytest, and nose
https://pypi.python.org/pypi/nose/ --> new projects should use py.test or
nose2
https://github.com/nose-devs/nose2
Pros
Build on top of unittests
Overpasses some of it's limits
Command line tool
Cons
nose not maintained any more --> nose2
Not native
Under development (nose2)
23 / 26
Python unittests overview
24 / 26
Conclusion
Doctests != py.test
Doctests are the natural way, how to test your code and how to document
it
Doctests should be used for documentation, not for testing
py.test seems to be current leading testing framework
Event /me knows, what is the difference between doctests and py.test
25 / 26
That's all folks
#jachymc
jachym.cepicky at opengeolabs dot cz
26 / 26

More Related Content

What's hot

PythonOOP
PythonOOPPythonOOP
PythonOOP
Veera Pendyala
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
Simon Hoyle
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
Hans-Jürgen Schönig
 
Advanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & moreAdvanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & more
Lukas Fittl
 
Statistical computing 01
Statistical computing 01Statistical computing 01
Statistical computing 01
Kevin Chun-Hsien Hsu
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
Rajkumar Asohan, PMP
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
Rsquared Academy
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
Guixing Bai
 
Intro
IntroIntro
Five
FiveFive
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Raman Kannan
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
R intro 20140716-advance
R intro 20140716-advanceR intro 20140716-advance
R intro 20140716-advance
Kevin Chun-Hsien Hsu
 
Quick reference for hql
Quick reference for hqlQuick reference for hql
Quick reference for hql
Rajkumar Asohan, PMP
 
Quick reference for solr
Quick reference for solrQuick reference for solr
Quick reference for solr
Rajkumar Asohan, PMP
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
Raman Kannan
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
Sveta Smirnova
 
Quick reference for HBase shell commands
Quick reference for HBase shell commandsQuick reference for HBase shell commands
Quick reference for HBase shell commands
Rajkumar Asohan, PMP
 
M11 bagging loo cv
M11 bagging loo cvM11 bagging loo cv
M11 bagging loo cv
Raman Kannan
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
Riyaj Shamsudeen
 

What's hot (20)

PythonOOP
PythonOOPPythonOOP
PythonOOP
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
 
Advanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & moreAdvanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & more
 
Statistical computing 01
Statistical computing 01Statistical computing 01
Statistical computing 01
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Intro
IntroIntro
Intro
 
Five
FiveFive
Five
 
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
Chapter 2: R tutorial Handbook for Data Science and Machine Learning Practiti...
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
R intro 20140716-advance
R intro 20140716-advanceR intro 20140716-advance
R intro 20140716-advance
 
Quick reference for hql
Quick reference for hqlQuick reference for hql
Quick reference for hql
 
Quick reference for solr
Quick reference for solrQuick reference for solr
Quick reference for solr
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
Quick reference for HBase shell commands
Quick reference for HBase shell commandsQuick reference for HBase shell commands
Quick reference for HBase shell commands
 
M11 bagging loo cv
M11 bagging loo cvM11 bagging loo cv
M11 bagging loo cv
 
Demystifying cost based optimization
Demystifying cost based optimizationDemystifying cost based optimization
Demystifying cost based optimization
 

Viewers also liked

PyWPS-4.0.0
PyWPS-4.0.0PyWPS-4.0.0
PyWPS-4.0.0
Jachym Cepicky
 
Descriptors In Python
Descriptors In PythonDescriptors In Python
Descriptors In Python
Amit Upadhyay
 
Lazy evaluation in Python
Lazy evaluation in PythonLazy evaluation in Python
Lazy evaluation in Python
Rahul Pydimukkala
 
Function arguments In Python
Function arguments In PythonFunction arguments In Python
Function arguments In Python
Amit Upadhyay
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
Greg DeKoenigsberg
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
Sujith Kumar
 
Generators: The Final Frontier
Generators: The Final FrontierGenerators: The Final Frontier
Generators: The Final Frontier
David Beazley (Dabeaz LLC)
 
Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)
David Beazley (Dabeaz LLC)
 
An Introduction to Python Concurrency
An Introduction to Python ConcurrencyAn Introduction to Python Concurrency
An Introduction to Python Concurrency
David Beazley (Dabeaz LLC)
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
Seth Familian
 

Viewers also liked (10)

PyWPS-4.0.0
PyWPS-4.0.0PyWPS-4.0.0
PyWPS-4.0.0
 
Descriptors In Python
Descriptors In PythonDescriptors In Python
Descriptors In Python
 
Lazy evaluation in Python
Lazy evaluation in PythonLazy evaluation in Python
Lazy evaluation in Python
 
Function arguments In Python
Function arguments In PythonFunction arguments In Python
Function arguments In Python
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 
Generators: The Final Frontier
Generators: The Final FrontierGenerators: The Final Frontier
Generators: The Final Frontier
 
Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)
 
An Introduction to Python Concurrency
An Introduction to Python ConcurrencyAn Introduction to Python Concurrency
An Introduction to Python Concurrency
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 

Similar to Python testing-frameworks overview

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
bcoca
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
Rsquared Academy
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTap
Rodolphe Quiédeville
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
SmartTools
 
GDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしようGDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしよう
Satoshi Noda
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?
Ben Hall
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
Rainer Schuettengruber
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
ACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
ACM Bay Area Data Mining Workshop: Pattern, PMML, HadoopACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
ACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
Paco Nathan
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
Paul King
 
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
Vani Kandhasamy
 
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
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
FarhanAhmade
 
Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
Eric Hogue
 

Similar to Python testing-frameworks overview (20)

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTap
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
GDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしようGDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしよう
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
 
ACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
ACM Bay Area Data Mining Workshop: Pattern, PMML, HadoopACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
ACM Bay Area Data Mining Workshop: Pattern, PMML, Hadoop
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
 
Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
 

More from Jachym Cepicky

Switch from shapefile
Switch from shapefileSwitch from shapefile
Switch from shapefile
Jachym Cepicky
 
What is the price of open source
What is the price of open sourceWhat is the price of open source
What is the price of open source
Jachym Cepicky
 
Testing web application with Python
Testing web application with PythonTesting web application with Python
Testing web application with Python
Jachym Cepicky
 
Danube hack 2015 - Open (-data, -communities)
Danube hack 2015 - Open (-data, -communities)Danube hack 2015 - Open (-data, -communities)
Danube hack 2015 - Open (-data, -communities)
Jachym Cepicky
 
Push it through the wire
Push it through the wirePush it through the wire
Push it through the wire
Jachym Cepicky
 
How Prague is opening data
How Prague is opening dataHow Prague is opening data
How Prague is opening data
Jachym Cepicky
 
Webgis, Cloud computing, OGC OWS
Webgis, Cloud computing, OGC OWSWebgis, Cloud computing, OGC OWS
Webgis, Cloud computing, OGC OWS
Jachym Cepicky
 
Co může udělat vaše firma pro open source
Co může udělat vaše firma pro open sourceCo může udělat vaše firma pro open source
Co může udělat vaše firma pro open source
Jachym Cepicky
 
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidé
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidéOtevřené standardy, Otevřená data, Otevřený software, Otevření lidé
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidé
Jachym Cepicky
 
Úvod do otevřená geoinfrastruktury
Úvod do otevřená geoinfrastrukturyÚvod do otevřená geoinfrastruktury
Úvod do otevřená geoinfrastruktury
Jachym Cepicky
 
PyWPS Status report
PyWPS Status reportPyWPS Status report
PyWPS Status report
Jachym Cepicky
 
Geosense Geoportal
Geosense GeoportalGeosense Geoportal
Geosense Geoportal
Jachym Cepicky
 
Sdílené intelektuální spoluvlastnictví
Sdílené intelektuální spoluvlastnictvíSdílené intelektuální spoluvlastnictví
Sdílené intelektuální spoluvlastnictví
Jachym Cepicky
 
Co brání většímu rozšíření open source nástrojů
Co brání většímu rozšíření open source nástrojůCo brání většímu rozšíření open source nástrojů
Co brání většímu rozšíření open source nástrojů
Jachym Cepicky
 
Open Source JavaScript Mapping Framework
Open Source JavaScript Mapping FrameworkOpen Source JavaScript Mapping Framework
Open Source JavaScript Mapping Framework
Jachym Cepicky
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS Workshop
Jachym Cepicky
 
Cepicky os-mapping-frameworks
Cepicky os-mapping-frameworksCepicky os-mapping-frameworks
Cepicky os-mapping-frameworks
Jachym Cepicky
 

More from Jachym Cepicky (20)

Switch from shapefile
Switch from shapefileSwitch from shapefile
Switch from shapefile
 
What is the price of open source
What is the price of open sourceWhat is the price of open source
What is the price of open source
 
Testing web application with Python
Testing web application with PythonTesting web application with Python
Testing web application with Python
 
Danube hack 2015 - Open (-data, -communities)
Danube hack 2015 - Open (-data, -communities)Danube hack 2015 - Open (-data, -communities)
Danube hack 2015 - Open (-data, -communities)
 
Push it through the wire
Push it through the wirePush it through the wire
Push it through the wire
 
How Prague is opening data
How Prague is opening dataHow Prague is opening data
How Prague is opening data
 
Webgis, Cloud computing, OGC OWS
Webgis, Cloud computing, OGC OWSWebgis, Cloud computing, OGC OWS
Webgis, Cloud computing, OGC OWS
 
Co může udělat vaše firma pro open source
Co může udělat vaše firma pro open sourceCo může udělat vaše firma pro open source
Co může udělat vaše firma pro open source
 
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidé
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidéOtevřené standardy, Otevřená data, Otevřený software, Otevření lidé
Otevřené standardy, Otevřená data, Otevřený software, Otevření lidé
 
Úvod do otevřená geoinfrastruktury
Úvod do otevřená geoinfrastrukturyÚvod do otevřená geoinfrastruktury
Úvod do otevřená geoinfrastruktury
 
PyWPS Status report
PyWPS Status reportPyWPS Status report
PyWPS Status report
 
Geosense Geoportal
Geosense GeoportalGeosense Geoportal
Geosense Geoportal
 
Cepicky pywps4
Cepicky pywps4Cepicky pywps4
Cepicky pywps4
 
Sdílené intelektuální spoluvlastnictví
Sdílené intelektuální spoluvlastnictvíSdílené intelektuální spoluvlastnictví
Sdílené intelektuální spoluvlastnictví
 
Co brání většímu rozšíření open source nástrojů
Co brání většímu rozšíření open source nástrojůCo brání většímu rozšíření open source nástrojů
Co brání většímu rozšíření open source nástrojů
 
Open Source JavaScript Mapping Framework
Open Source JavaScript Mapping FrameworkOpen Source JavaScript Mapping Framework
Open Source JavaScript Mapping Framework
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS Workshop
 
Cepicky osgeocz
Cepicky osgeoczCepicky osgeocz
Cepicky osgeocz
 
Cepicky os-mapping-frameworks
Cepicky os-mapping-frameworksCepicky os-mapping-frameworks
Cepicky os-mapping-frameworks
 
Cepicky wikikonf-2013
Cepicky wikikonf-2013Cepicky wikikonf-2013
Cepicky wikikonf-2013
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

Python testing-frameworks overview

  • 1. What is doctest? Python testing frameworks overview 1 / 26
  • 2. What am I doing here? 2 / 26
  • 3. What am I doing here? Facts Jachym Cepicky GIS (maps in computer) Open source software Not facts not a tester not educated software engineer nor GIS educated 3 / 26
  • 4. What am I doing here? Me: confused py.test with doctest 4 / 26
  • 7. Everybody loves to tests. 7 / 26
  • 8. Everybody has heard, that using TDD is the only way how to write code loves to tests. 8 / 26
  • 10. The fact Writing tests ... does make sense 10 / 26
  • 11. Summary Making sure, that the system meets the requirements that guided its design and development, responds correctly to all kinds of inputs, performs its functions within an acceptable time, is sufficiently usable, can be installed and run in its intended environments, and achieves the general result its stakeholders desire. https://en.wikipedia.org/wiki/Software_testing 11 / 26
  • 12. Testing in Python - overview 12 / 26
  • 13. It's pretty cool and easy to test in Python 13 / 26
  • 14. Unittest https://docs.python.org/3/library/unittest.html originally inspired by JUnit (inspired by SUnit for Smalltalk, since 1998) https://shebanator.com/2007/08/21/a-brief-history-of-test-frameworks/ Pros Native framework Testing methods Supported everywhere Auto discovery of test classes and functions Cons Classes Testing methods Complicated (for some people) Lack of Group fixtures (specified environment for a whole group) Still better to separate testing code from business logic Unit-test oriented 14 / 26
  • 15. import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('foo'.upper(), 'FOO') def test_isupper(self): self.assertTrue('FOO'.isupper()) self.assertFalse('Foo'.isupper()) def test_split(self): s = 'hello world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): s.split(2) if __name__ == '__main__': unittest.main() 15 / 26
  • 16. $ python my_unittest.py .F. ====================================================================== FAIL: test_split (__main__.TestStringMethods) ---------------------------------------------------------------------- Traceback (most recent call last): File "neco.py", line 14, in test_split self.assertEqual(s.split(), ['hellox', 'world']) AssertionError: Lists differ: ['hello', 'world'] != ['hellox', 'world'] First differing element 0: 'hello' 'hellox' - ['hello', 'world'] + ['hellox', 'world'] ? + ---------------------------------------------------------------------- Ran 3 tests in 0.001s FAILED (failures=1) 16 / 26
  • 17. py.test http://doc.pytest.org/en/latest/ Pros Plugins HTML output Simpler and more straight-forward syntax Auto discovery of test functions Distributed Cons Not native Can get complicated too (decorators) 17 / 26
  • 18. def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 18 / 26
  • 19. $ python3 -m pytest my_pytest.py ============================================ test session starts ============================================ platform linux -- Python 3.5.2+, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 rootdir: /tmp, inifile: collected 2 items neco.py F. ================================================= FAILURES ================================================== ________________________________________________ test_answer ________________________________________________ def test_answer(): > assert inc(3) == 5 E assert 4 == 5 E + where 4 = inc(3) neco.py:5: AssertionError ==================================== 1 failed, 1 passed in 0.03 seconds ===================================== 19 / 26
  • 20. Doctest https://docs.python.org/3/library/doctest.html Pros Native Tests are (can be) part of class and method documentation Can be in separated text (e.g. README) files Supported by Sphinx Cons Not suitable for larger testing systems No fixtures 20 / 26
  • 21. def unique_words(page): ''' Returns set of the unique words in list of lines of text Example: >>> from StringIO import StringIO >>> fileText = """the cat sat on the mat ... the mat was ondur the cat ... one fish two fish red fish ... blue fish ... This fish has a yellow car ... This fish has a yellow star""" >>> file = StringIO(fileText) >>> page = file.readlines() >>> words = unique_words(page) >>> print sorted(list(words)) ["This", "a", "blue", "car", "cat", "fish", "has", "mat", "on", "ondur", "one", "red", "sat", "star", "the", "two", "was", "yellow"] >>> ''' return set(word for line in page for word in line.split()) def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test() 21 / 26
  • 22. $ python2 my_doctest.py ********************************************************************** File "neco.py", line 16, in __main__.unique_words Failed example: print sorted(list(words)) Expected: ["This", "a", "blue", "car", "cat", "fish", "has", "mat", "on", "ondur", "one", "red", "sat", "star", "the", "two", "was", "yellow"] Got: ['This', 'a', 'blue', 'car', 'cat', 'fish', 'has', 'mat', 'on', 'ondur', 'one', 'red', 'sat', 'star', 'the', 'two', 'was', 'yellow'] ********************************************************************** 1 items had failures: 1 of 6 in __main__.unique_words ***Test Failed*** 1 failures. 22 / 26
  • 23. nose (nose2) nose extends unittest to make testing easier smart developer should get familiar doctest, unittest, pytest, and nose https://pypi.python.org/pypi/nose/ --> new projects should use py.test or nose2 https://github.com/nose-devs/nose2 Pros Build on top of unittests Overpasses some of it's limits Command line tool Cons nose not maintained any more --> nose2 Not native Under development (nose2) 23 / 26
  • 25. Conclusion Doctests != py.test Doctests are the natural way, how to test your code and how to document it Doctests should be used for documentation, not for testing py.test seems to be current leading testing framework Event /me knows, what is the difference between doctests and py.test 25 / 26
  • 26. That's all folks #jachymc jachym.cepicky at opengeolabs dot cz 26 / 26