SlideShare a Scribd company logo
1 of 12
Download to read offline
Testing in Style - Reducing Barriers to Higher CodeTesting in Style - Reducing Barriers to Higher Code
Quality Through AutomationQuality Through Automation
Moritz E. Beber
Postdoc in Computational Biology
Novo Nordisk Foundation Center for Biosustainability
Why Test at All?Why Test at All?
The more problems caught in development, the less your users (you!) see in
production
High test coverage gives you con dence to refactor code
Similarly, it makes it easier for others to contribute because they easily know
whether or not they broke something
Writing testable code typically leads to more modular code
Aspects of TestingAspects of Testing
Follow a style ( )
Statically analyze your code
Unit tests
Integration tests
pep8 (https://www.python.org/dev/peps/pep-0008/)
Live DemoLive Demo
Contrived example: a simple calculator
git clone https://github.com/Midnighter/calculator-demo
Package StructurePackage Structure
├── src
│   └── demo
│   ├── __init__.py
│   └── operators.py
└── tests
├── test_integration
└── test_unit
└── test_operators.py
WhyWhy src??
It can get messy
https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure
(https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure)
http://andrewsforge.com/article/python-new-package-landscape/
(http://andrewsforge.com/article/python-new-package-landscape/)
TopicsTopics
flake8-docstrings
pytest.mark.parametrize
pytest-raises
hypothesis
package data
coverage
Important Topics not CoveredImportant Topics not Covered
xtures (https://docs.pytest.org/en/latest/ xture.html)
pdb (https://docs.pytest.org/en/latest/usage.html#dropping-to-pdb-python-
debugger-on-failures)
mocking (https://docs.pytest.org/en/latest/monkeypatch.html)
Invoking ToxInvoking Tox
Run all the de ned tox environments:
Select a speci c environment:
If your tox.ini de nes it, you can provide additional arguments after -- :
tox
tox -e py36
commands =
pytest --cov=demo {posargs: tests}
tox -e py36 -- --cov-report=html tests
Non-installed ProjectsNon-installed Projects
If you are testing a project that is not an installable package, you will want to change your
tox.ini :
You can then install dependencies normally, e.g., via a requirements le:
or additionally allow global site-packages in the [testenv] section:
[tox]
envlist = ...
skipsdist = true
[testenv]
skip_install = true
deps =
-rrequirements.txt
sitepackages = true
Continuous Integration & DeploymentContinuous Integration & Deployment
Travis CI (https://travis-ci.org/)
Circle CI (https://circleci.com/)
AppVeyor (https://www.appveyor.com/)
Jenkins (https://jenkins.io/)
GitLab CI (https://about.gitlab.com/product/continuous-integration/)
Thank YouThank You
For a complete example, please take a look at the
branch.
full-implementation
(https://github.com/Midnighter/calculator-demo/tree/full-implementation)
Feel free to reach out to me:
midnighter@posteo.net (mailto:midnighter@posteo.net?subject=Python
testing)
Midnighter (https://github.com/Midnighter/)
@me_beber (https://twitter.com/me_beber)
Moritz Beber (https://www.linkedin.com/in/moritz-beber-b597a55a/)

More Related Content

Recently uploaded

Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Lisi Hocke
 

Recently uploaded (20)

GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
Abortion Clinic in Midrand [(+27832195400*)]🏥Safe Abortion Pills In Midrand |...
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
微信号购买
微信号购买微信号购买
微信号购买
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Testing in Style - Reducing Barriers to Higher Code Quality Through Automation

  • 1. Testing in Style - Reducing Barriers to Higher CodeTesting in Style - Reducing Barriers to Higher Code Quality Through AutomationQuality Through Automation Moritz E. Beber Postdoc in Computational Biology Novo Nordisk Foundation Center for Biosustainability
  • 2. Why Test at All?Why Test at All? The more problems caught in development, the less your users (you!) see in production High test coverage gives you con dence to refactor code Similarly, it makes it easier for others to contribute because they easily know whether or not they broke something Writing testable code typically leads to more modular code
  • 3. Aspects of TestingAspects of Testing Follow a style ( ) Statically analyze your code Unit tests Integration tests pep8 (https://www.python.org/dev/peps/pep-0008/)
  • 4. Live DemoLive Demo Contrived example: a simple calculator git clone https://github.com/Midnighter/calculator-demo
  • 5. Package StructurePackage Structure ├── src │   └── demo │   ├── __init__.py │   └── operators.py └── tests ├── test_integration └── test_unit └── test_operators.py
  • 6. WhyWhy src?? It can get messy https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure (https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure) http://andrewsforge.com/article/python-new-package-landscape/ (http://andrewsforge.com/article/python-new-package-landscape/)
  • 8. Important Topics not CoveredImportant Topics not Covered xtures (https://docs.pytest.org/en/latest/ xture.html) pdb (https://docs.pytest.org/en/latest/usage.html#dropping-to-pdb-python- debugger-on-failures) mocking (https://docs.pytest.org/en/latest/monkeypatch.html)
  • 9. Invoking ToxInvoking Tox Run all the de ned tox environments: Select a speci c environment: If your tox.ini de nes it, you can provide additional arguments after -- : tox tox -e py36 commands = pytest --cov=demo {posargs: tests} tox -e py36 -- --cov-report=html tests
  • 10. Non-installed ProjectsNon-installed Projects If you are testing a project that is not an installable package, you will want to change your tox.ini : You can then install dependencies normally, e.g., via a requirements le: or additionally allow global site-packages in the [testenv] section: [tox] envlist = ... skipsdist = true [testenv] skip_install = true deps = -rrequirements.txt sitepackages = true
  • 11. Continuous Integration & DeploymentContinuous Integration & Deployment Travis CI (https://travis-ci.org/) Circle CI (https://circleci.com/) AppVeyor (https://www.appveyor.com/) Jenkins (https://jenkins.io/) GitLab CI (https://about.gitlab.com/product/continuous-integration/)
  • 12. Thank YouThank You For a complete example, please take a look at the branch. full-implementation (https://github.com/Midnighter/calculator-demo/tree/full-implementation) Feel free to reach out to me: midnighter@posteo.net (mailto:midnighter@posteo.net?subject=Python testing) Midnighter (https://github.com/Midnighter/) @me_beber (https://twitter.com/me_beber) Moritz Beber (https://www.linkedin.com/in/moritz-beber-b597a55a/)