#287 Testing without dependencies, mocking in Python
1 hr 3 min
We know our unit tests should be relatively independent from other parts of the system. For example, running a test shouldn't generally call a credit card possessing API and talk to a database when your goal is just to test the argument validation.

And yet, your method does all three of those and more. What do you do? Some languages use elaborate dependency passing frameworks that go under the banner of inversion of control (IoC) and dependency injections (DI). In Python, the most common fix is to temporarily redefine what those two functions do using patching and mocking.

On this episode, we welcome back Anna-Lena Pokes to talk us through the whole spectrum of test doubles, dummies, mocks, and more.

Links from the show

Anna-Lena's personal site: alpopkes.com
100 Days of Code episode: talkpython.fm/186
Anna-Lena on Github: github.com
PyCon talk from Lisa Road (2018) - “Demystifying the patch function”: youtube.com
PyCon talk from Edwin Jung (2019) - Mocking and Patching Pitfalls: youtube.com
Keynote talk “Finding Magic in Python” (about magical universe
project): youtube.com
Blog post about mocking in Python: alpopkes.com
Stackoverflow post on difference between stubs and mocks: stackoverflow.com
Freezegun project: github.com
KI Macht Schule (AI goes to school): ki-macht-schule.de
Code Combat: codecombat.com
PDB++: github.com

Sponsors

Linode
Monday.com
Talk Python Training
Python Bytes
Python Bytes
Michael Kennedy and Brian Okken
#208 Dependencies out of control? Just pip chill.
Sponsored by us! Support our work through: * Our courses at Talk Python Training * Test & Code Podcast * Patreon Supporters Brian #1: pip-chill - Make requirements with only the packages you need * Ricardo Bánffy * Like pip freeze but lists only the packages that are not dependencies of installed packages. * Will be great for creating requirements.txt files that look like the ones you would write by hand. * I wish it had an option to not list itself, but pip-chill | grep -v pip-chill works. * What do I have installed? (foo) $ pip freeze appdirs==1.4.4 black==20.8b1 click==7.1.2 mypy-extensions==0.4.3 ... * No really, what did I myself install? (foo) $ pip-chill black==20.8b1 pip-chill==1.0.0 * Without versions? (foo) $ pip-chill --no-version black pip-chill * What did those things install as dependencies? (foo) $ pip-chill -v --no-version black pip-chill # appdirs # Installed as dependency for black # click # Installed as dependency for black ... Michael #2: Windows update broke NumPy * Sent in by Daniel Mulkey * A recent Windows update broke some behavior that I think OpenBLAS (used by NumPy) relied on. * There's a Developer Community thread here. * I am a NumPy developer. We have been trying to track down a strange issue where after updating to windows 10 2004, suddenly code that worked no longer works. Here is the NumPy issue and here is the corresponding issue in OpenBLAS. The problem can be summarized: when calling fmod, something is changed so that much later calling an OpenBLAS assembly routine fails. The only difference I can see in the registers that visual studio exposes is that after the call to fmod, register ST(0) is set to NAN. * Steve Dower and other Microsoft people have commented. * The fix is slated to take until January 2021 to be released, though there are workarounds for some scenarios. * Matt P. posted a workaround: * For all those at home following along and looking for a quick fix, NumPy has released a bugfix 1.19.3 to work around this issue. The bugfix broke something else on Linux, so we had to revert the fix in release 1.19.4, but you can still install the 1.19.3 via * pip install numpy==1.19.3. * Note this is only works around the way this bug crashes NumPy (technically, in OpenBLAS which is shipped with NumPy), and may not fix all your problems related to this bug, Microsoft’s help is needed to do that. Brian #3: Build Plugins with Pluggy * kracekumar * Blog post related to talks given at PyGotham and PyCon India * Pluggy is the plugin library used by pytest * Article * starts with a CLI application that has one output format. * Need is for more formats, implemented as plugins. * Quick look at pluggy architecture of host/caller/core system and plugin/hook. * Also plugin manager, hook specs, and hook implementations. * Walks through the changes to the application needed to support plugins. * I’ve been waiting for an article on pluggy, and this is nice. * But I admit I’m still a little lost. I guess I need to watch one of the presentations and try to build something with pluggy. Michael #4: LINQ in Python * via Adam: I seem to recall that Michael had a C# background, so this might be of interest: * Bringing LINQ-like expressions to Python with linqit * Example: last_hot_pizza_slice = programmers.where(lambda e:e.experience > 15) .except_for(elon_musk) .of_type(Avi) .take(3) # [[HTML_REMOVED], [HTML_REMOVED], [HTML_REMOVED]] .select(lambda avi:avi.lunch) # [[HTML_REMOVED], [HTML_REMOVED], [HTML_REMOVED]] .where(lambda p:p.is_hot() and p.origin != 'Pizza Hut'). .last() # [HTML_REMOVED] .slices.last() # [HTML_REMOVED] * Also interesting asq: https://github.com/sixty-north/asq Brian #5: Klio : a framework for processing audio files or any binary files, at large scale * Recently open sourced by Spotify * An article about it * Klio is based on Apache Beam and allows * integration with cloud processing engines * open graph of job dependencies * batch and streaming pipelines * goals: * large-file input/output * scalability, reproducibility, efficiency * closer collaboration between researchers and engineers * uses Python * Obviously useful for Spotify, but they are hoping it will help with other audio research and applications. Michael #6: Collapsing code cells in Jupyter Notebooks * via Marco Gorelli * You mentioned in that episode that you'd like to have a way of collapsing code cells in Jupyter Notebooks so you can export them as reports - incidentally, I wrote a little blog post about how to do that - in case it's useful/of interest to you, here it is! * Basically get a static HTML file that is the static notebook output but can start with the code cells collapsed and can toggle their visibility. Extras Michael: * New Apple Silicon macs? * Bot tweets: twitter.com/MichelARenard/status/1324269474544029696 Joke: By Richard Cairns Q: Why did the data scientist get in trouble with Animal Welfare? A: She was caught trying to import pandas. “10e engineeeeeeeeers are the future.” - detahq
30 min
Command Line Heroes
Command Line Heroes
Red Hat
Mark Dean: The Inventor Who Made the Computer Personal
Dr. Mark Dean has a superpower. He wasn’t born with it. He wasn’t exposed to high levels of radiation. It’s a power he learned from his father. And because of it, he was able to revolutionize the personal computer. David Bradley explains how in the 1980s, IBM had a reputation for building big, enterprise mainframes. No one believed IBM could make a competitive PC. But that’s exactly what “Project Chess” was tasked with creating. Tony Hey describes the monumental shift in strategy it was for IBM to enter the PC market. Pete Martinez and Dennis Moeller recount their days working with Mark on the skunkworks project. And how IBM's strategy for creating a computer in under a year changed the personal computing industry forever—opening it to innovators outside the walls of IBM. Mark Dean holds 3 of the 9 patents for the IBM 5150—the first IBM PC—including the revolutionary ISA bus. He then went on to lead the team that created the first gigahertz microprocessor, and eventually taught at the University of Tennessee. Mwamba Bowa shares her most cherished lesson from the inventor—how to cultivate that super power for herself. Clips of Mark Dean courtesy of Susan "Suze" Shaner, Principal of Sage Leadership Strategies, from a Comcast Cable interview, November 2009, and from the American Museum of Science & Energy featured talk, August 2019. If you want to read up on some of our research on Dr. Mark Dean, you can check out all our bonus material over at redhat.com/commandlineheroes. Follow along with the episode transcript.
27 min
Kubernetes Podcast from Google
Kubernetes Podcast from Google
Adam Glick and Craig Box
KubeCon NA 2020, with Stephen Augustus
Join us for all the news from KubeCon NA 2020, and a conversation with conference co-chair Stephen Augustus. Stephen is a Senior Open Source Engineer on the VMware Tanzu team, a chair of Kubernetes’ SIG Release, and a leader in many other parts of the project, past and present. Do you have something cool to share? Some questions? Let us know: * web: kubernetespodcast.com * mail: kubernetespodcast@google.com * twitter: @kubernetespod Chatter of the week * The kākāpō wins Bird of the Year * We’re off for 2 weeks. See you on December 8! News of the week * Cisco acquires Banzai Cloud * CNCF announces Cloud Native Survey 2020 results * Red Hat: New edge features, industrial AI/ML blueprint and AWS launch * CNCF End User Tech Radar for storage * New End User benefits * Envoy Mobile joins the CNCF * New sandbox projects * cert-manager * cdk8s * Kyverno * OpenKruise * Pravega * SchemaHero * Tinkerbell * k8ssandra from Datastax * Episode 98 with Sam Ramji * k0s from Mirantis * Solo.io announces Gloo Mesh Enterprise and rebrands products * Episode 55, with Idit Levine * Pinniped * Shipa launches Ketch * Kinvolk launches Headlamp * The SPIFFE book “Solving The Bottom Turtle” * Episode 45, with Andrew Jessup * Anthos Developer Sandbox * GKE ingress features * Ambassador Labs takes in $18m and launches v1.9 * Tanzu SQL: Postgres on Kubernetes * Lightning round: * Accurics extends Terrascan * AWS adds containers to Lightsail * Arrikto takes $10m in funding * Brobridge releases Gravity * CircleCI runner is GA * Cloud66 for agencies and multiple database support * Cloudflare Origin CA cert-manager plugin * Cloudical Vanillastack * Cloudify version 5.1 * Codefresh launches GitOps 2.0 features * Commvault backup-as-a-service * Diamanti Spektra 3.1 and customer portal * Dynatrace PurePath 4 * Elastisys Compliant Kubernetes * The Fairwinds Kubernetes Maturity Model * Garden takes “seed” funding * Gremlin adds soundproofing * Humio Operator * Instana adds observability tools on Kubernetes * Intuit runs TurboTax on Kubernetes * Kioxia announces a new storage offering * Kubecost adds features for monitoring outside a cluster * KubeMQ adds automatic network creation * Kubermatic updates KubeOne to v1.1 * Kubernative SINA * Kublr 1.19 * Lablup announced Backend.ai 20.09 RC * Magalix launches KubeAdvisor 2.0 * Mayadata launches Kubera Propel and Kubera Chaos * Mirantis adds extensions to Lens * Puppet Labs adds Relay to Puppet Enterprise * Reblaze announces Curiefense to add WAF to Envoy * Replicates wants to help you Troubleshoot * Styra adds new editions to DAS * Sysdig introduces Kubernetes-native network security (ZTNSK) and partners with IBM Cloud * TrilioVault for Kubernetes v2.0 * Zerto for Kubernetes * Google Open Source Live Kubernetes Links from the interview * KubeCon NA 2020 * Episode 117, with Constance Caramanolis * CNCF Twitch * SIG Friday: ping Stephen for the current link * Slack * CNCF Slack * Kubernetes Slack * Hallway Track * Kubernetes Podcast chat * CoreOS * CoreOS Tectonic * CoreOS acquired by Red Hat * Tectonic on Azure * SIG Azure * SIG Release * SIG PM (retired) * Kubernetes Enhancement Process * Receipts process KEP * Sidecar containers - KEP closed! * Production readiness review * Episode 10, with Josh Berkus and Tim Pepper * Release managers * Black Lives Matter announcement banner * Better announcements * Kubernetes Naming working group * Inclusive Naming project * Dan Kohn memorial * Stephen Augustus on Twitter and on the web
53 min
CoRecursive: Coding Stories
CoRecursive: Coding Stories
Adam Gordon Bell - Full Stack Web Developer
The Birth of Unix with Brian Kernighan
As Brian Kernighan said “UNIX since the start has become a vehicle for creating and using programming languages.” Brian initiated work on what would become the UNIX system. He helped develop it to run on a minicomputer and would eventually be ported to other computers. In this episode, Brain will go in-depth on how the UNIX was built. Episode Page Episode Transcript “If you wanted, you could go sit in your office and think deep thoughts or program, or write on your own blackboard or whatever, but then come back to the common space when you wanted to.“ - Brian Kernighan “I found it easier to program when I was trying to figure out the logic for myself rather than trying to figure out where in the infinite stack of documentation was the function I needed. So for me, programming is more like creating something rather than looking it up, and too much of today's programming is more like looking it up.” - Brian Kernighan “If what I find challenging or hard or whatever is also something that other people find hard or challenging or whatever, then if I do something that will improve my lot, I'm perhaps improving their lot at the same time.” - Brian Kernighan Links: Brian's Homepage Book: Unix: A History and a Memoir Book: Millions, Billions, Zillions: Defending Yourself in a World of Too Many Numbers Book: Understanding the Digital World: What You Need to Know about Computers, the Internet, Privacy, and Security
51 min
Google Cloud Platform Podcast
Google Cloud Platform Podcast
Google Cloud Platform
2020 Year End Wrap Up
This week, four of the podcast’s greatest hosts come together to celebrate all of the fun and informative episodes we’ve been privileged to do this year! Join Mark Mirchandani, Jon Foust, Priyanka Vergadia, and Brian Dorsey as we talk about our favorite guests and shows, some cool things that happened this year, and what we’re looking forward to in 2021! Cool things of the week * A Giant List of Google Cloud Resources blog * Google Cloud 4 Words site Our favorite episodes * Jon’s Favorites * GCP Podcast Episode 212: Data Management with Amy Krishnamohan podcast * GCP Podcast Episode 237: NVIDIA with Bryan Catanzaro podcast * Priyanka’s Favorite * GCP Podcast Episode 240: reCAPTCHA Enterprise with Kelly Anderson + Spring ML Potholes with Eric Clark podcast * Mark’s Favorites * GCP Podcast Episode 242: NASA and FDL with James Parr and Madhulika Guhathakurta podcast * GCP Podcast Episode 217: Cost Optimization with Justin Lerma and Pathik Sharma podcast * GCP Podcast Episode 228: Fastly with Tyler McMullen podcast * Brian’s Favorites * GCP Podcast Episode 223: Voice Coding with Emily Shea and Ryan Hileman podcast * GCP Podcast Episode 233: Bare Metal Solution with James Harding and Gurmeet Goindi podcast * GCP Podcast Episode 212: Data Management with Amy Krishnamohan podcast Sound Effects Attribution * “Bad Beep” by RicherLandTV of Freesound.org * “Small Group Laugh 6” by Tim.Kahn of Freesound.org * “It’s Always Night in Space” by JamesSilvera of HDInteractive.com * “Easy Cheesy” by LoboLoco of FreeMusicArchive.org
36 min
More episodes
Search
Clear search
Close search
Google apps
Main menu