

Test & Code
Brian Okken
The Python Test Podcast hosted by Brian Okken
Episodes
Mentioned books

Mar 6, 2021 • 11min
147: Testing Single File Python Applications/Scripts with pytest and coverage
Have you ever written a single file Python application or script? Have you written tests for it? Do you check code coverage?This is the topic of this weeks episode, spurred on by a listener question.The questions:For single file scripts, I'd like to have the test code included right there in the file. Can I do that with pytest?If I can, can I use code coverage on it?The example code discussed in the episode: script.pydef foo():
return 5
def main():
x = foo()
print(x)
if __name__ == '__main__': # pragma: no cover
main()
## test code
# To test:
# pip install pytest
# pytest script.py
# To test with coverage:
# put this file (script.py) in a directory by itself, say foo
# then from the parent directory of foo:
# pip install pytest-cov
# pytest --cov=foo foo/script.py
# To show missing lines
# pytest --cov=foo --cov-report=term-missing foo/script.py
def test_foo():
assert foo() == 5
def test_main(capsys):
main()
captured = capsys.readouterr()
assert captured.out == "5\n"
Suggestion by @cfbolz if you need to import pytest:if __name__ == '__main__': # pragma: no cover
main()
else:
import pytest

Feb 28, 2021 • 48min
146: Automation Tools for Web App and API Development and Maintenance - Michael Kennedy
Building any software, including web apps and APIs requires testing. There's automated testing, and there's manual testing. In between that is exploratory testing aided by automation tools. Michael Kennedy joins the show this week to share some of the tools he uses during development and maintenance.We talk about tools used for semi-automated exploratory testing. We also talk about some of the other tools and techniques he uses to keep Talk Python Training, Talk Python, and Python Bytes all up and running smoothly. We talk about:Postmanngroksitemap link testingscripts for manual processesusing failover servers during maintenance, redeployments, etcgitHub webhooks and scripts to between fail over servers and production during deployments automaticallyfloating IP addresses services to monitor your site: StatusCake, BetterUptimethe affect of monitoring on analyticscrash reporting: Rollbar, Sentryresponse timesload testing: LocusLinks:Python Bytes PodcastTalk Python To Me PodcastTalk Python TrainingPostmanngrokStatusCakeBetter UptimeRollbarSentryLocust12 requests per second in Python

Feb 18, 2021 • 48min
145: For Those About to Mock - Michael Foord
A discussion about mocking in Python with the original contributor of unittest.mock, Michael Foord.Of course we discuss mocking and unittest.mock. We also discuss:testing philosophyunit testing and what a unit isTDDwhere Michael's towel is, and what colorMicheal was instrumental in the building of testing tools for Python, and continues to be a pragmatic source of honest testing philosopy in a field that has a lot of contradictory information.Links:unittest.mock - Python docsMocks Aren't Stubs - Martin Fowlerpytest-mockmock.patchAutospeccingArrange Act Asserttesting-in-python mailing listClassical and Mockist Testing — Classical and Mockist Testing Test First Programming / Test First Developmentepisode 102: Cosmic Python, TDD, testing and external dependencies - Harry Percivalepisode 132: mocking in Python - Anna-Lena Popkespytestunittest - Python docspytest assert usage30 best practices for software development and testing | Opensource.com

Feb 13, 2021 • 53min
144: TDD in Science - Martin Héroux
Test Driven Development, TDD, is not easy to incorporate in your daily development. Martin and Brian discuss TDD and testing and Martin's experience with testing, TDD, and using it for code involved with scientific research. We discuss lots of topics around this, including:What is TDD?Should research software be tested in order to be trusted?Time pressure and the struggle to get code done quickly. How do you make time for tests also?Is testing worth it for code that will not be reused?Sometimes it's hard to know how to test something.Maybe people should learn to test alongside learning how to code.A desire for a resource of testing concepts for non-CS people.Are the testing needs and testing information needs different in different disciplines? Biology, Physics, Astrophysics, etc. Do they have different testing needs?Do we need a "how to test" resource for each?Special Guest: Martin Héroux.Links:Joy Division Album Coverepisode 140: Testing in Scientific Research and Academia - Martin Héroux — Martin's previous episode.

Feb 7, 2021 • 39min
143: pytest markers - Anthony Sottile
Completely nerding out about pytest markers with Anthony Sottile.Some of what we talk about:Running a subset of tests with markers.Using marker expressions with and, or, not, and parentheses.Keyword expressions also can use and, or, not, and parentheses.Markers and pytest functionality that use mark, such as parametrize, skipif, etc.Accessing markers with itermarkers and get_closest_marker through item.Passing values, metadata through markers to fixtures or hook functions.Links:Registering markersslow marker example in pytest documentation — Control skipping of tests according to command line optionpytest-repeat · PyPIsource code for pytest-repeatWorking with custom markers — pytest documentationUsing -k expr to select tests based on their nameMarker revamp and iteration, Historical Notes — pytest documentation

Jan 25, 2021 • 34min
142: MongoDB - Mark Smith
MongoDB is possibly the most recognizable NoSQL document database. Mark Smith, a developer advocate for MongoDB, answers my many questions about MongoDB. We cover some basics, but also discuss some advanced features that I never knew about before this conversation.Special Guest: Mark Smith.Links:MongoDBEverything You Know About MongoDB is Wrong!Implementing Event Sourcing and CQRS pattern with MongoDB

Dec 30, 2020 • 30min
141: Visual Testing - Angie Jones
Visual Testing has come a long way from the early days of x,y mouse clicks and pixel comparisons. Angie Jones joins the show to discuss how modern visual testing tools work and how to incorporate visual testing into a complete testing strategy. Some of the discussion:Classes of visual testing: problems with pixel to pixel testingDOM comparisons, css, html, etc.AI driven picture level testing, where failures look into the DOM to help describe the problem. Where visual testing fits into a test strategy.Combining "does this look right" visual testing with other test workflows."A picture is worth a thousand assertions" - functional assertions built into visual testing.Baselining pictures in the test workflow.Also discussed:automation engineerTest Automation UniversityLinks:Test Automation University

Dec 18, 2020 • 47min
140: Testing in Scientific Research and Academia - Martin Héroux
Scientists learn programming as they need it. Some of them learn it in college, but even if they do, that's not their focus. It's not surprising that sharing the software used for scientific research and papers is spotty, at best. And what about testing? We'd hope that the software behind scientific research is tested. But why would we expect that? We're lucky if CS students get a class or two that even mentions automated tests. Why would we expect other scientists to just know how to test their code?Martin works in research and this discussion is about software and testing in scientific research and academia.Special Guest: Martin Héroux.Links:Python Testing with pytest: Simple, Rapid, Effective, and ScalableTest Driven Development: By ExampleMy reaction to "Is TDD Dead?" - Python TestingMartinHeroux/pliffy: Plotting differences with PythonPyBites Code ChallengesPython MorselsMartin Héroux (@martin_heroux) / TwitterScientifically SoundMartin Héroux - Google Scholarspike2py · PyPIpytest-mpl · PyPI

Dec 4, 2020 • 36min
139: Test Automation: Shifting Testing Throughout the Software Lifecycle - Nalin Parbhu
Talking with Nalin Parbhu about the software evolution towards more test automation and the creation of Infuse and useMango.We talk a software development and "shift left" where automated tests and quality checks have moved earlier into the software lifecycle.Software approaches and where quality fits inShift leftTest automationRoles of software developers, SDETs (software development engineer in test), testers, QA, etc.Developers doing testing and devopsAutomated testing vs manual testingRegression testing, UI testing, black bock testingUnit testing, white box, API, end to end testingUser acceptance testing (UAT)Mullet Methodology (Agile at the front, Waterfall at the back)Waterwheel Methodology (Requirements -> iterative development -> QA)What's an agile team?Developer resistance to testingManifesto for agile software developmentIterative developmentAdapting to changeAgility: being able to change course quicklySpecial Guests: Nalin Parbhu and Ola Omiyale.

Nov 19, 2020 • 29min
138: Mutation Testing in Python with mutmut - Anders Hovmöller
Your test suite tells you about the quality of your code under test. Mutation testing is a way to tell you about the quality of your test suite. Anders Hovmöller wrote mutmut for mutation testing in Python, and can be used with pytest, unittest, and others. In this episode, Anders explains mutation testing, how mutation testing with mutmut works, and good workflows.Special Guest: Anders Hovmöller.Links:mutmut · PyPIcosmic-ray · PyPIMutPy · PyPIparso · PyPImutmut documentationNed Batchelder article on mutmut