DiscoverTest & Code : Python Testing for Software Engineering
Test & Code :  Python Testing for Software Engineering
Claim Ownership

Test & Code : Python Testing for Software Engineering

Author: Brian Okken

Subscribed: 3,251Played: 44,137
Share

Description

Test & Code is a weekly podcast hosted by Brian Okken.
The show covers a wide array of topics including software engineering, development, testing, Python programming, and many related topics.
When we get into the implementation specifics, that's usually Python, such as Python packaging, tox, pytest, and unittest. However, well over half of the topics are language agnostic, such as data science, DevOps, TDD, public speaking, mentoring, feature testing, NoSQL databases, end to end testing, automation, continuous integration, development methods, Selenium, the testing pyramid, and DevOps.
132 Episodes
Reverse
Using mock objects during testing in Python. Anna-Lena joins the podcast to teach us about mocks and using unittest.mock objects during testing. We discuss: - the different styles of using mocks - pros and cons of mocks - dependency injection - adapter pattern - mock hell - magical universe - and much more Special Guest: Anna-Lena Popkes.
Some people avoid writing tests. Some drudge through it painfully. There is a better way. In this episode, I'm going to share some advice from Luke Plant on how to "Test Smarter, Not Harder" (https://lukeplant.me.uk/blog/posts/test-smarter-not-harder/).
virtualenv supports six shells: bash, csh, fish, xonsh, cmd, posh. Each handles prompts slightly differently. Although the virtualenv custom prompt behavior should be the same across shells, Brian Skinn noticed inconsistencies. He set out to fix those inconsistencies. That was the start of an adventure in open source collaboration, shell prompt internals, difficult test problems, and continuous integration quirks. Brian Skinn initially noticed that on Windows cmd, a space was added between a prefix defined by --prompt and the rest of the prompt, whereas on bash no space was added. For reference, there were/are three nominal virtualenv prompt modification behaviors, all of which apply to the prompt changes that are made at the time of virtualenv activation: If the environment variable VIRTUAL_ENV_DISABLE_PROMPT is defined and non-empty at activation time, do not modify the prompt at all. Otherwise: If the --prompt argument was supplied at creation time, use that argument as the prefix to apply to the prompt; or, If the --prompt argument was not supplied at creation time, use the default prefix of "({{ envname }}) " as the prefix (the environment folder name surrounded by parentheses, and with a trailing space after the last paren. Special Guest: Brian Skinn.
I asked people on twitter to fill in "How do I test _____?" to find out what people want to know how to test. Lots of responses. David Lord agreed to answer them with me. In the process, we come up with lots of great general advice on how to test just about anything. Specific Questions people asked: What makes a good test? How do you test web app performance? How do you test cookie cutter templates? How do I test my test framework? How do I test permission management? How do I test SQLAlchemy models and pydantic schemas in a FastAPI app? How do I test warehouse ETL code? How do I test and mock GPIO pins on hardware for code running MicroPython on a device? How do I test PyQt apps? How do I test web scrapers? Is it the best practice to put static html in your test directory or just snippets stored in string variables? What's the best way to to test server client API contracts? How do I test a monitoring tool? We also talk about: What is the Flask testing philosophy? What do Flask tests look like? Flask and Pallets using pytest Code coverage Some of the resulting testing strategies: Set up some preconditions. Run the function. Get the result. Don't test external services. Do test external service failures. Don't test the frameworks you are using. Do test your use of a framework. Use open source projects to learn how something similar to your project tests things. Focus on your code. Focus on testing your new code. Try to architect your application such that actual GUI testing is minimal. Split up a large problem into smaller parts that are easier to test. Nail down as many parts as you can. Special Guest: David Lord.
Software tests should be order independent. That means you should be able to run them in any order or run them in isolation and get the same result. However, system state often gets in the way and order dependence can creep into a test suite. One way to fight against order dependence is to randomize test order, and with pytest, we recommend the plugin pytest-randomly to do that for you. The developer that started pytest-randomly and continues to support it is Adam Johnson, who joins us today to discuss pytest-randomly and another plugin he also wrote, called pytest-reverse. Special Guest: Adam Johnson.
Many people have been working from home now that are not used to working from home. Or at least are working from home more than they ever did before. That's definitely true for me. Even though I've been working from home since March, I wanted some tips from people who have been doing it longer. Julian Sequeira, of PyBites fame, has been working from home for about a year. Reuven Lerner, an amazing Python trainer, has been working from home for much longer. We originally had a big list of WFH topics. But we had so much fun with the tips and tricks part, that that's pretty much the whole episode. But there's lots of great tips and tricks, so I'm glad we focused on that. Special Guests: Julian Sequeira and Reuven Lerner.
Researches and others using data science and software need to follow solid software engineering practices. This is a message that Joel Grus has been promoting for some time. Joel joins the show this week to talk about data science, software engineering, and even Fizz Buzz. Topics include: Software Engineering practices and data science Difficulties with Jupyter notebooks Code reviews on experiment code Unit tests on experiment code Finding bugs before doing experiments Tests for data pipelines Tests for deep learning models Showing researchers the value of tests by showing the bugs found that wouldn't have been found without them. "Data Science from Scratch" book Showing testing during teaching Data Science "Ten Essays on Fizz Buzz" book Meditations on Python, mathematics, science, engineerign and design Testing Fizz Buzz Different algorithms and solutions to an age old interview question. If not Fizz Buzz, what makes a decent coding interview question. pytest hypothesis Math requirements for data science Special Guest: Joel Grus.
pytest 6 is out. Specifically, 6.0.1, as of July 31. And there's lots to be excited about. Anthony Sottile joins the show to discuss features, improvements, documentation updates and more. Full release notes / changelog (https://docs.pytest.org/en/stable/changelog.html) Some of what we talk about: How to update (at least, how I do it) Run your test suites with 5.4.3 or whatever the last version you were using Update to 6 Run again. Same output? Probably good. If there are any warnings, maybe fix those. You can also run with pytest -W error to turn warnings into errors. Then find out all the cool stuff you can do now New Features pytest now supports pyproject.toml files for configuration. but remember, toml syntax is different than ini files. mostly quotes are needed pytest now includes inline type annotations and exposes them to user programs. Most of the user-facing API is covered, as well as internal code. New command-line flags --no-header and --no-summary A warning is now shown when an unknown key is read from a config INI file. The --strict-config flag has been added to treat these warnings as errors. New required_plugins configuration option allows the user to specify a list of plugins, including version information, that are required for pytest to run. An error is raised if any required plugins are not found when running pytest. Improvements You can now pass output to things like less and head that close the pipe passed to them. thank you!!! Improved precision of test durations measurement. use --durations=10 -vv to capture and show durations Rich comparison for dataclasses and attrs-classes is now recursive. pytest --version now displays just the pytest version, while pytest --version --version displays more verbose information including plugins. --junitxml now includes the exception cause in the message XML attribute for failures during setup and teardown. Improved Documentation Add a note about --strict and --strict-markers and the preference for the latter one. Explain indirect parametrization and markers for fixtures. Bug Fixes Deprecations Trivial/Internal Changes Breaking Changes you might need to care about before upgrading PytestDeprecationWarning are now errors by default. Check the deprecations and removals (https://docs.pytest.org/en/latest/deprecations.html) page if you are curious. -k and -m internals were rewritten to stop using eval(), this results in a few slight changes but overall makes them much more consistent testdir.run().parseoutcomes() now always returns the parsed nouns in plural form. I'd say that's an improvement Special Guest: Anthony Sottile.
pip is the package installer for Python. Often, when you run pip, especially the first time in a new virtual environment, you will see something like: WARNING: You are using pip version 20.1.1; however, version 20.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. And you should. Because 20.2 has a new dependency resolver. Get in the habit, until October, of replacing pip install with pip install --use-feature=2020-resolver. This flag is new in the 20.2 release. This new pip dependency resolver is the result of a lot of work. Five of the people involved with this work are joining the show today: Bernard Tyers, Nicole Harris, Paul Moore, Pradyun Gedam, and Tzu-ping Chung. We talk about: * pip dependency resolver changes * user experience research and testing * crafting good error messages * efforts to improve the test suite * testing pip with pytest * some of the difficulties with testing pip * working with a team on a large project * working with a large code base * bringing new developers into a large project Special Guests: Bernard Tyers, Nicole Harris, Paul Moore, Pradyun Gedam, and Tzu-ping Chung.
Lots of Python projects are starting to use GitHub Actions for Continous Integration & Deployment (CI/CD), as well as other workflows. Tania Allard, a Senior Cloud Developer Advocate at Microsoft, joins the show to answer some of my questions regarding setting up a Python project to use Actions. Some of the topics covered: How to get started with GitHub Actions for a Python project? What are workflow files? Does it matter what the file name is called? Can I have / Should I have more than one workflow? Special Guest: Tania Allard.
A great resume is key to landing a great software job. There's no surprise there. But so many people make mistakes on their resume that can very easily be fixed. Randall Kanna is on the show today to help us understand how to improve our resumes, and in turn, help us have better careers. Special Guest: Randall Kanna.
Len Wanger works on industrial 3D printers. And I was pleased to find out that there's a bunch of Python in those printers as well. In this episode we talk about: 3D printers What are the different types of 3D printers? Where are 3D printed industrial parts being used? Why use one type of additive manufacturing over another? Python in 3D printing hardware. What are Finite State Machines, FSMs? Benefits of FSMs for testing, logging, and breaking a complex behavior into small testable parts. Benefits of simulation in writing and testing software to control hardware. Special Guest: Len Wanger.
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints. Typer is a library for building CLI applications, also based on Python type hints. Type hints and many other details are intended to make it easier to develop, test, and debug applications using FastAPI and Typer. The person behind FastAPI and Typer is Sebastián Ramírez. Sebastián is on the show today, and we discuss: FastAPI Rest APIs Swagger UI Future features of FastAPI Starlette Typer Click Testing with Typer and Click Typer autocompletion Typer CLI Special Guest: Sebastián Ramírez.
There's stuff going on in Python packaging and pyproject.toml. Brett and I talk about some upcoming work on Python packaging, such as: editable installs the need for standardization configuration of other tools in pyproject.toml And then get off on tangents and talk about: why it's good to have packages like pip, toml, setuptools, wheel, etc not part of the standard library should we remove some stuff from the standard library the standard library using unittest for testing the standard library why not hypothesis I didn't bring up "why not pytest?" but you know I was thinking it. why CPython and not C++Python and more Special Guest: Brett Cannon.
Code Coverage or Test Coverage is a way to measure what lines of code and branches in your code that are utilized during testing. Coverage tools are an important part of software engineering. But there's also lots of different opinions about using it. - Should you try for 100% coverage? - What code can and should you exclude? - What about targets? I've been asked many times what I think about code coverage or test coverage. This episode is a train of thought brain dump on what I think about code coverage. We'll talk about: - how I use code coverage to help me write source code - line coverage and branch coverage - behavior coverage - using tests to ask and answer questions about the system under test - how to target coverage just to the code you care about - excluding code - good reasons and bad reasons to exclude code And also the Pareto Principle or 80/20 rule, and the law of diminishing returns and how that applies (or doesn't) to test coverage.
The Python extension for VS Code is most downloaded extension for VS Code. Brett Cannon is the manager for the distributed development team of the Python extension for VS Code. In this episode, Brett and I discuss the Python extension and VS Code, including: pytest support virtual environment support how settings work, including user and workspace settings multi root projects testing Python in VS Code debugging and pydevd jump to cursor feature upcoming features Special Guest: Brett Cannon.
pytest plugins are an amazing way to supercharge your test suites, leveraging great solutions from people solving test problems all over the world. In this episode Michael and I discuss 15 favorite plugins that you should know about. We also discuss fixtures and plugins and other testing tools that work great with pytest * tox * GitHub Actions * Coverage.py * Selenium + splinter with pytest-splinter * Hypothesis And then our list of pytest plugins: 1. pytest-sugar 1. pytest-cov 1. pytest-stress 1. pytest-repeat 1. pytest-instafail 1. pytest-metadata 1. pytest-randomly 1. pytest-xdist 1. pytest-flake8 1. pytest-timeout 1. pytest-spec 1. pytest-picked 1. pytest-freezegun 1. pytest-check 1. fluentcheck That last one isn't a plugin, but we also talked about pytest-splinter at the beginning. So I think it still counts as 15. Special Guest: Michael Kennedy.
One of the great things about attending in person coding conferences, such as PyCon, is the hallway track, where you can catch up with people you haven't seen for possibly a year, or maybe even the first time you've met in person. Nina is starting something like the hallway track, online, on twitch, and it's already going, so check out the first episode of Python Tea (https://www.twitch.tv/videos/635831555). Interesting coincidence is that this episode is kind of like a hallway track discussion between Nina and Brian. We've had Nina on the show a couple times before, but it's been a while. In 2018, we talked about Mentoring on episode 44 (https://testandcode.com/44). In 2019, we talked about giving Memorable Tech Talks in episode 71 (https://testandcode.com/71). In this episode, we catch up with Nina, find out what she's doing, and talk about a bunch of stuff, including: Live Coding Online Conferences Microsoft Python team Python Tea, an online hallway track Q&A with Python for VS Code team Python on hardware Adafruit Device Simulator Express CircuitPython Tricking out your command prompt Zsh and Oh My Zsh Emacs vs vi key bindings for shells Working from home Special Guest: Nina Zakharenko.
"The mission of the Python Software Foundation is to promote, protect, and advance the Python programming language, and to support and facilitate the growth of a diverse and international community of Python programmers." That's a lot of responsibility, and to that end, the PSF Board Directors help out quite a bit. If you want to be a part of the board, you can. There's an election coming up right around the corner and you gotta get your nomination in by May 31. You can also join the PSF if you want to vote for who gets to be part of the board. But what does it really mean to be on the Board, and what are some of the things the PSF does? To help answer those questions, I've got Ewa Jodlowska, the PSF Executive Director, and Christopher Neugebauer, a current board member, on the show today. I've also got some great links in the show notes if we don't answer your questions and you want to find out more. Special Guests: Christopher Neugebauer and Ewa Jodlowska.
Technical debt has to be dealt with on a regular basis to have a healthy product and development team. The impacts of technical debt include emotional drain on engineers and slowing down development and can adversely affect your hiring ability and retention. But really, what is technical debt? Can we measure it? How do we reduce it, and when? James Smith, the CEO of Bugsnag, joins the show to talk about technical debt and all of these questions. Special Guest: James Smith.
loading
Comments (6)

Max Ong Zong Bao

I would be interested to invite you as keynote for PyCon Singapore in June and I would love to know more on your PyTest online courses when it releases.

Jan 3rd
Reply

Александр Михеев

Such a great episode! I've even listened to it twice

Dec 9th
Reply

Eduardo Costa

I enjoyed this episode. Hope more episodes on this subject.

Mar 15th
Reply

Leora Juster

react tables

Jan 12th
Reply

GreatBahram

another great episode

Dec 16th
Reply

Antonio Andrade

Thanks for sharing these good tips

Dec 9th
Reply
Download from Google Play
Download from App Store