POPULARITY
Topics covered in this episode: Talk Python rewritten in Quart PyPI now supports digital attestations Django Rusty Templates PEP 639 is now supported by PYPI Extras Joke Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training The Complete pytest Course Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org / @mkennedy.codes (bsky) Brian: @brianokken@fosstodon.org / @brianokken.bsky.social Show: @pythonbytes@fosstodon.org / @pythonbytes.fm (bsky) Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Monday at 10am PT. Older video versions available there too. Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it. Michael #1: Talk Python rewritten in Quart Rewrote all of talkpython.fm in Quart (10k lines of code total, 4k changed) Considered FastAPI Litestar Django Hugo Static Site + Python Flask Discussed the multistage upgrade / conversion process Automating tests for all 1,000 pages Brian #2: PyPI now supports digital attestations Dustin Ingram “Attestations provide a verifiable link to an upstream source repository: By signing with the identity of the upstream source repository, such as in the case of an upload of a project built with GitHub Actions, PyPI's support for digital attestations defines a strong and verifiable association between a file on PyPI and the source repository, workflow, and even the commit hash that produced and uploaded the file. Additionally, publishing attestations to a transparency log helps mitigate against both compromise of PyPI and compromise of the projects themselves.” For maintainers If using GH Actions and Trusted Publishing make sure you use pypa/gh-action-pypi-publish, version v1.11.0 or newer that's it If not “Support for automatic attestation generation and publication from other Trusted Publisher environments is planned.” “While not recommended, maintainers can also manually generate and publish attestations.” See also PyPI Introduces Digital Attestations to Strengthen Python Package Security by Sarah Gooding Are we PEP 740 yet? Michael #3: Django Rusty Templates by Lily Foote An experimental reimplementation of Django's templating language in Rust. Goals 100% compatibility of rendered output. Error reporting that is at least as useful as Django's errors. Improved performance over Django's pure Python implementation. Brian #4: PEP 639 is now supported by PYPI from Brett Cannon PEP 639 – Improving License Clarity with Better Package Metadata For project metadata, use these fields: license and license-files: Examples license field [project] license = "MIT" [project] license = "MIT AND (Apache-2.0 OR BSD-2-clause)" [project] license = "MIT OR GPL-2.0-or-later OR (FSFUL AND BSD-2-Clause)" [project] license = "LicenseRef-Proprietary" Examples of license-files: [project] license-files = ["LICEN[CS]E*", "AUTHORS*"] [project] license-files = ["licenses/LICENSE.MIT", "licenses/LICENSE.CC0"] [project] license-files = ["LICENSE.txt", "licenses/*"] [project] license-files = [] Extras Brian: Playground Wisdom: Threads Beat Async/Await - interesting read from Armin Ronacher about different language abstractions around concurrency. PythonTest.com Discord community is now live Launched last week, as of this morning we've got 89 members Anyone already a pythontest community member has received an invite Anyone can join through courses.pythontest.com Everything at pythontest.com is 20% off through Dec 2 with code turkeysale2024 “Python Testing with pytest” eBook 40% off through Dec 2, use code turkeysale2024 Michael: Python 3.14.0a2 released Starter packs: Michael's Python people: https://bsky.app/starter-pack/mkennedy.codes/3lbdnupl26e2x Directory: https://blueskydirectory.com/starter-packs/all Joke: curl - heavy metal style!
If you haven't tried running automated tests, especially with pytest, in VS Code recently, you should take another look.The Python for VS Code interface for testing, especially for pytest, has changed recently. On this episode we discuss the change with the software engineer working on the pytest changes, Eleanor Boyd, and the product manager, Courtney Webster. Links from the episode:Blog post announcing the rewrite Code repo for questions, comments, issues etc The Complete pytest CourseLevel up your testing skills and save time during coding and maintenance.Check out courses.pythontest.com
Topics covered in this episode: Granian pytest 8 is here Assorted Docker Goodies New GitHub Copilot Research Finds 'Downward Pressure on Code Quality' Extras Joke Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training The Complete pytest Course Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org Brian: @brianokken@fosstodon.org Show: @pythonbytes@fosstodon.org Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too. Michael #1: Granian via Andy Shapiro and Bill Crook A Rust HTTP server for Python applications. Granian design goals are: Have a single, correct HTTP implementation, supporting versions 1, 2 (and eventually 3) Provide a single package for several platforms Avoid the usual Gunicorn + uvicorn + http-tools dependency composition on unix systems Provide stable performance when compared to existing alternatives Could use better logging But making my own taught me maybe I prefer that! Originates from the Emmett framework. Brian #2: pytest 8 is here Improved diffs: Very verbose -vv is a colored diff, instead of a big chunk of red. Python code in error reports is now syntax-highlighted as Python. The sections in the error reports are now better separated. Diff for standard library container types are improved. Added more comprehensive set assertion rewrites for comparisons other than equality ==, with the following operations now providing better failure messages: !=, =, . Improvements to -r for xfailures and xpasses Report tracebacks for xfailures when -rx is set. Report captured output for xpasses when -rX is set. For xpasses, add - in summary between test name and reason, to match how xfail is displayed. This one was important to me. Massively helps when checking/debugging xfail/xpass outcomes in CI. Thanks to Fabian Sturm, Bruno Oliviera, and Ran Benita for help to get this release. Lots of other improvements See full changelog for all the juicy details. And then upgrade and try it out! pip install -U pytest Michael #3: Assorted Docker Goodies OrbStack Say goodbye to slow, clunky containers and VMs OrbStack is the fast, light, and easy way to run Docker containers and Linux. Develop at lightspeed with our Docker Desktop alternative. Podman Podman is an open source container, pod, and container image management engine. Podman makes it easy to find, run, build, and share containers. Manage containers (not just Podman.) Podman Desktop allows you to list, view, and manage containers from multiple supported container engines* in a single unified view. Gain easy access to a shell inside the container, logs, and basic controls. Works on Podman, Docker, Lima, kind, Red Hat OpenShift, Red Hat OpenShift Developer Sandbox. CasaOS Your Personal Cloud OS. Community-based open source software focused on delivering simple personal cloud experience around Docker ecosystem. Also have the ZimaCube hardware (Personal cloud. Re-invented.) Brian #4: New GitHub Copilot Research Finds 'Downward Pressure on Code Quality' David Ramel Regarding “…the quality and maintainability of AI-assisted code compared to what would have been written by a human.” Q: "Is it more similar to the careful, refined contributions of a Senior Developer, or more akin to the disjointed work of a short-term contractor?" A: "We find disconcerting trends for maintainability. Code churn -- the percentage of lines that are reverted or updated less than two weeks after being authored -- is projected to double in 2024 compared to its 2021, pre-AI baseline. We further find that the percentage of 'added code' and 'copy/pasted code' is increasing in proportion to 'updated,' 'deleted,' and 'moved 'code. In this regard, AI-generated code resembles an itinerant contributor, prone to violate the DRY-ness [don't repeat yourself] of the repos visited." Extras Brian: Did I mention pytest 8? Just pip install -U pytest today And if you want to learn pytest super fast, check out The Complete pytest Course or grab a copy of the book, Python Testing with pytest Michael: I'd like to encourage people to join our mailing list. We have some fun plans and some of them involve our newsletter. It's super private, no third parties, no spam and is based on my recent Docker and Listmonk work. Big release for Pydantic, 2.6. New essay: Use Custom Search Engines Way More Joke: Pushing to main Junior vs Senior engineer
Topics covered in this episode: OverflowAI Switching to Hatch Alpha release of the Ruff formatter What is wrong with TOML? Extras Joke Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest, full course Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org Brian: @brianokken@fosstodon.org Show: @pythonbytes@fosstodon.org Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too. Michael #1: OverflowAI Integration of generative AI into our public platform, Stack Overflow for Teams, and brand new product areas, like an IDE integration. Have a conversation about the search results and proposed answer with GenAI Coming with IDE integration too. Check out the video on their page for some more detail than the article. Brian #2: Switching to Hatch Oliver Andrich Hatch has some interesting features Template built from hatch new myproject includes isolating dev, test, lint virtual environments. Each env can have scripts Test matrix ala tox, but possibly easier to express complex matrices. May not even need tox then, but then now you have hatch. A way to specify which optional dependencies needed for default environment. Notes from Brian One premise is that lots of projects are now using hatch. I don't know if that's true. A quick spot check of a few projects include projects that use hatchling. While hatchling is the back end to hatch, they are not the same. I use hatchling a lot now, but haven't picked up using hatch. But I do want to try it more after reading this article. Michael #3: Alpha release of the Ruff formatter vis Sky Kasko Charlie Marsh announced that an alpha version of a Ruff formatter has been released in Ruff v0.0.289. The formatter is designed to be a drop-in replacement for Black, but with an excessive focus on performance and direct integration with Ruff. Sky says: I can't find any benchmarks that have been released yet, but I did some extremely unscientific testing and found the Ruff formatter to be around 5 to 10 times faster than Black when running on already-formatted code or in a small codebase, and 75 times faster when running on a large codebase of unformatted code. (The second outcome probably isn't very important since most people would not often be formatting thousands of lines of completely unformatted code.) For more info, see the README: https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_formatter/README.md Brian #4: What is wrong with TOML? Colm O'Connor Suggested by Will McGugan This is a comparison of TOML vs StrictYAML under the use case of “readable story tests”. TLDR; For smallish things like pyproject.toml, toml is fine. For huge files, something like StrictYAML may be less horrible. from Brian: Short answer: Nothing, unless you're doing crazy things with it. Re “readable story tests”: WTF? Neither of these are something I'd like to maintain. Extras Brian: Python Testing with pytest, the course New intro video to explain what the course is about Using Teachable video like notes, mini-viewer, and speed controls Chapter on “Testing Strategy” is next Michael: HTMX + Django: Modern Python Web Apps, Hold the JavaScript Course Coding in Rust? Here's a New IDE by JetBrains Delightful Machine Learning Apps with Gradio out on Talk Python Joke: The 5 stages of debugging
Topics covered in this episode: Omnivore app Djangonaut.space Server-side hot reload Python in Excel Extras Joke Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Python People Podcast Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org Brian: @brianokken@fosstodon.org Show: @pythonbytes@fosstodon.org Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too. Michael #1: Omnivore app Omnivore is the free, open source, read-it-later app for serious readers. Distraction free. Privacy focused. Open source. Designed for knowledge workers and lifelong learners. Save articles, newsletters, and documents and read them later — focused and distraction free. Add notes and highlights. Organize your reading list the way you want and sync it across all your devices. Syncs with popular Personal Knowledge Management systems including Logseq and Obsidian Wait, what's Logseq? :) A privacy-first, open-source platform for knowledge management and collaboration. Kinda like Notion? Brian #2: Djangonaut.space “Where contributors launch” This is a group mentoring program where individuals will work self-paced in a semi-structured learning environment over the course of three months. Djangonauts are members of the community who wish to level up their current Django code contributions and potentially take on leadership roles in Django in the future. Michael #3: Server-side hot reload Thanks to Alex Riviere for some improvements Bill Mill suggests websockets and Adam Johnson points he built something like this for Django (sorta) with django-browser-reload To make it work just: Include this script in your web projects for dev-time auto reloading of web browser when any change is detected in content. Works across all web technologies, built out on a FastAPI / Tailwind project. General workflow looks like: Edit the source CSS file Tailwind watcher generates a built CSS file Built CSS file is included the Python web HTML template Template appends a hash ID for the state of the CSS file Changes to the source CSS thus trigger a change in the final ID New ID means the page contents change and the script does a reload Even works for static resources if you put a “version” indicator on them: [HTML_REMOVED] [HTML_REMOVED] Brian #4: Python in Excel Anaconda working with Microsoft to have Python built in to Excel. “Python in Excel is currently in preview and is subject to change based on feedback. To use this feature, join the Microsoft 365 Insider Program and choose the Beta Channel Insider level.” from Microsoft Support article: Getting started with Python in Excel Extras Brian: Working on videos for “Ch3 : pytest Fixtures” for the Python Testing with pytest Course Bundle Adding some drawings and some more bonus videos. Thanks to everyone who's signed up already. I've pushed the 20% discount out till the end of August. I also finally listed it on pythontest.com/courses Also lots of new interviews for pythonpeople.fm, and I'm expecting at least one new episode of testandcode.com this week. It's going to be a busy week. Michael: PyCon Sweden CFP is open Be on Talk Python around Mobile Apps? Joke: The Password Game KennyLog-in.com - secure password generator
Topics covered in this episode: Differentiating between writing down dependencies to use packages and for packages themselves PythonMonkey Quirks of Python package versioning bear-type Extras Joke Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Python People Podcast Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org Brian: @brianokken@fosstodon.org Show: @pythonbytes@fosstodon.org Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too. Brian #1: Differentiating between writing down dependencies to use packages and for packages themselves Brett Cannon Why can't we just use pyproject.toml and stop using requirements.txt? Nope. At least not yet. They're currently for different things. pyproject.toml There's project.dependencies and project.optional-dependencies.tests that kinda would work for listing dependencies for an app. But you can't say pip install -r pyproject.toml. It doesn't work. And that's weird. project is intended for packaged projects. requirements.txt for applications and other non-packaged projects It has specific versions works great with pip What then? Either we stick with requirements.txt Or we invent some other file, maybe requirements.toml? Or maybe (Brian's comment), add something like [application] and application.dependencies and application.optional-dependencies.tests to pyproject.toml Michael #2: PythonMonkey PythonMonkey is a Mozilla SpiderMonkey JavaScript engine embedded into the Python VM, using the Python engine to provide the JS host environment. This product is in an early stage, approximately 80% to MVP as of July 2023. It is under active development by Distributive. External contributions and feedback are welcome and encouraged. It will enable JavaScript libraries to be used seamlessly in Python code and vice versa — without any significant performance penalties. Call Python packages like NumPy from within a JavaScript library, or use NPM packages like [crypto-js](https://www.npmjs.com/package/crypto-js) directly from Python. Executing WebAssembly modules in Python becomes trivial using the WebAssembly API and engine from SpiderMonkey. More details in Will Pringle's article. Brian #3: Quirks of Python package versioning Seth Larson Yes, we have SemVer, 1.2.3, and CalVer, 2023.6.1, and suffixes for pre-release, 1.2.3pre1. But it gets way more fun than that, if you get creative Here's a few v is an optional prefix, like v.1.0 You can include an “Epoch” and separate it from the version with a !, like 20!1.2.3 Local versions with alphanumerics, periods, dashes, underscores, like 1.0.0+ubuntu-1. PyPI rejects those. That's probably good. Long versions. There's no max length for a version number. How about 1.2.3.4000000000000000001? Pre, post, dev aren't mutually exclusive: 1.0.0-pre0-post0-dev0 More craziness in article - Michael #4: bear-type Beartype is an open-source PEP-compliant near-real-time pure-Python runtime type-checker emphasizing efficiency, usability, and thrilling puns. Annotate @beartype-decorated classes and callables with type hints. Call those callables with valid parameters: Transparent Call those callables with invalid parameters: Boom Traceback: raise exception_cls( beartype.roar.BeartypeCallHintParamViolation: @beartyped quote_wiggum() parameter lines=[b'Oh, my God! A horrible plane crash!', b'Hey, everybody! Get a load of thi...'] violates type hint list[str], as list item 0 value b'Oh, my God! A horrible plane crash!' not str. Extras Brian: Python Testing with Pytest Course Bundle: Limited Pre-Release Beta Use code PYTHONBYTES now through Aug 31for 20% discount (discount extended through the end of the month) What's a pre-release beta? There's a video. Check out the link. Error-tolerant pytest discovery in VSCode Finally! But you gotta turn it on. Also, I gotta talk to them about the proper non-capitalization of pytest. We're at RC1 for Python 3.12.0 Hard to believe it's that time of year again Michael: PyPI hires a Safety & Security Engineer, welcome Mike Fiedler PackagingCon October 26-28 Cloud Builders: Python Conf (born in Ukraine): September 6, 2023 | online Joke: Learning JavaScript
Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Connect with the hosts Michael: @mkennedy@fosstodon.org Brian: @brianokken@fosstodon.org Show: @pythonbytes@fosstodon.org Special guest: GUEST_PROFILE Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too. Michael #1: Ruff PyCharm plugin via John Hagen Ruff PyCharm plugin has great integration, it will highlight Ruff lint errors in the IDE as you type and you can even apply Alt+Enter (⌥⏎ on Mac) quick fixes through the IDE. Ruff will automatically fix the fixable issues. John also added additional PyCharm-specific instructions for black/Ruff Brian #2: Writing Python like it's Rust Kobzol Rust lessons guiding use of types and type hints in Python Add type hints tun function signatures Use dataclasses instead of tuples or dictionaries to increase clarity and type safety Union types to clarify | typing Michael #3: Pip 23.1 Released - Massive improvement to backtracking Pip 23.1 was released last month Highlight the significant improvement in backtracking that is part of the requirement resolver process in Pip. This process involves Pip finding a set of packages that meet your requirements and whose requirements themselves don't conflict. Prior to Pip 20.3, the default process for Pip would allow conflicting requirements to install if they were transitive dependencies where the last one specified would be the one installed. Once the new resolver was turned on by default it immediately hit problems where backtracking would get stuck for a long time. Pip separates out the resolution logic into a library called resolvelib. It had been discovered that there was a logical error under certain circumstances, and also there was a known better backtracking technique it could employ called backjumping. Both of these were recently fixed and implemented in resolvelib, which were then vendored in to Pip 23.1. Brian #4: Markdown Code Runner markdown-code-runner is a Python package that automatically executes code blocks within a Markdown file, including hidden code blocks, and updates the output in-place. Works with Python & Bash see also cog Extras Brian: Use code SPRING2023 to get 50% off “Python Testing with pytest, 2nd edition” before June 1. Michael: Python 3.12.0a7 is out python3 -m venv --upgrade-deps venv (via John Hagen) Talk submissions are now open for both remote and in-person talks at the 2023 PyConZA? The conference will be held on 5 and 6 October 2023 in Durban, South Africa. South Africa is GMT+2, so the times are convenient for Africa, Europe and much of Asia, although probably less so for the rest of the world. All details are on za.pycon.org - via Kim van Wik Trail discovery/riding apps onX offroad Gaia Picture of Michael on one of these trails Joke: User Inyerface
Test and Code podcast Python Testing with pytestDjango Testing Tutorial pytest-django Testing in Django: Official Docs awesome-django repo testing section PythonBytes 204 w/ Will and Carlton Support the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter.
Software Engineering Radio - The Podcast for Professional Software Developers
In this episode, we explore the popular pytest python testing tool with author Brian Okken, author of Python Testing with pytest. We start by discussing why pytest is so popular in the Python community: its focus on simplicity, readability, and developer ease-of-use; what makes pytest unique; the setup and teardown of tests using fixtures, parameterization, and the plugin ecosystem; mocking; why we should design for testing, and how to reduce the need for mocking; how to set up a project for testability; test-driven development, and designing your tests so that they support refactoring. Finally, we consider some complementary tools that can improve the python testing experience.
This week we talk about a "taboo" topic: the pursuit of chasing the bigger paycheque. We reflect on the (hidden) cost of this and what to take into consideration. As usual, we also share some cool wins and books we're reading. Join our Facebook group:https://www.facebook.com/groups/pybites- Live training coming in a few weeks ...What we're reading: Create Space, Blockchain Revolution, Refactoring 2nd ed, Brief Answers to the Big Questions (Here is a complete reading list of all books we've mentioned on the podcast)And a special shout-out to Brian Okken's Python Testing with pytest, Second Edition which we reviewed and thoroughly enjoyed. Great work Brian!Thanks for listening, for any feedback email us at info@pybit.es
Today on the show, we will be talking to Adam Byczkowski from Network to Code about code testing in network automation. This is an important topic that is often overlooked in Network Automation, especially if we are just getting our feet wet in the space. I was very happy to see Adam wrote about code testing in the network automation space via a 3-part blog series. I invited Adam on the show to talk about his journey, code testing, and testing in the network automation world. I know we will learn a lot from Adam. Let's dive right in! --- Show Notes Links ---Connect with Adam on LinkedIn: https://www.linkedin.com/in/adam-byczkowski-525568105/ Pytest in the Networking World (Parts 1 - 3): https://blog.networktocode.com/post/pytest-in-the-networking-world/https://blog.networktocode.com/post/pytest-in-the-netwoking-world-part-2/ https://blog.networktocode.com/post/pytest-in-the-netwoking-world-part-3/ NTC NetUtil (easy to understand tests): https://blog.networktocode.com/post/introducing-netutils/ Read Network to Code Blogs: https://blog.networktocode.com/Closing the Loop on Testing Network Changes: https://elegantnetwork.github.io/posts/closing-the-loop-testing/Python Testing with pytest by Brian Okken: https://pragprog.com/titles/bopytest2/python-testing-with-pytest-second-edition/ Coverage.py: https://coverage.readthedocs.io/en/6.1.2/ pytest plugins: https://docs.pytest.org/en/latest/how-to/plugins.html Other Resources: Pythontesting.netTest and Code Podcast: Testandcode.com --- Stay in Touch with Us ---Subscribe on YouTube: https://www.youtube.com/c/EricChouNetworkAutomationNerdsFollow Eric on Twitter: https://twitter.com/ericchou
Watch the live stream: Watch on YouTube About the show Sponsored by Datadog: pythonbytes.fm/datadog Michael #1: Physics Breakthrough as AI Successfully Controls Plasma in Nuclear Fusion Experiment Interesting break through using AI Is Python at the center of it? With enough digging, the anwswer is yes, and we love it! Brian #2: PEP 680 -- tomllib: Support for Parsing TOML in the Standard Library Accepted for Python 3.11 This PEP proposes basing the standard library support for reading TOML on the third-party library tomli Michael #3: Thread local threading.local: A class that represents thread-local data. Thread-local data are data whose values are thread specific. Just create an instance of local (or a subclass) and store attributes on it You can even subclass it. Brian #4: What is a generator function? Trey Hunner Super handy, and way easier than you think, if you've never written your own. Really, it's just a function that uses yield instead of return and supplies one element at a time instead of returning a list or dict or tuple or other large structure. Some details generator functions return generator objects generator objects are on pause and use the built in next() function to get next item. they raise StopIteration when done. Most generally used from for loops. Generator objects cannot be re-used when exhausted but you can get a new one with the next for loop you use. So, it's all good. Michael #5: dirty-equals via Will McGugan, by Samual Colvin Doing dirty (but extremely useful) things with equals. from dirty_equals import IsPositive assert 1 == IsPositive assert -2 == IsPositive # this will fail! user_data = db_conn.fetchrow('select * from users') assert user_data == { 'id': IsPositiveInt, 'username': 'samuelcolvin', 'avatar_file': IsStr(regex=r'/[a-z0-9-]{10}/example.png'), 'settings_json': IsJson({'theme': 'dark', 'language': 'en'}), 'created_ts': IsNow(delta=3), } Brian #6: Commitizen from the docs Command-line utility to create commits with your rules. Defaults: Conventional commits Display information about your commit rules (commands: schema, example, info) Bump version automatically using semantic versioning based on the commits. Read More Generate a changelog using Keep a changelog considering using for consistent commit message formatting can be used with python-semantic-release for automatic semantic versioning learned about it in 10 Tools I Wish I Knew When I Started Working with Python questions anyone using this or something similar? does this make sense for small to medium sized projects? or overkill? Extras: pytest book 40% off sale continues through March 19 for eBook Amazon lists the book as “shipping in 1-2 days”, as of March 2 Michael: Pronouncing the Python Walrus operator := as “becomes” Via John Sheehan: String methods startswith() and endswith() can take a tuple as its first argument that lets you check for multiple values with one call: >>> x = "abcdefg" >>> x.startswith(("ab", "cd", "ef"), 2) True Joke: CS Background
Watch the live stream: Watch on YouTube About the show Sponsored by us: Check out the courses over at Talk Python And Brian's book too! Brian #1: (draft) PEP 679 -- Allow parentheses in assert statements Pablo Galindo Salgado This is in draft, not approved, and not scheduled for any release But it seems like a really good idea to me. assert(1 == 2, "seems like it should fail") will always pass currently since the tuple (False,"seems like it should fail") is a non-empty tuple. Current Python will emit a warning >>> assert(1 == 2, "seems like it should fail") [stdin]:1: SyntaxWarning: assertion is always true, perhaps remove parentheses? But really, why not just change the language to allow assert with or without parens. Also would allow multi-line assert statements more easily: assert ( very very long expression, "very very long " "message", ) I hope this is a slam dunk and gets in ASAP. Michael #2: Everything I googled as a dev by Sophie Koonin In an attempt to dispel the idea that if you have to google stuff you're not a proper engineer, this is a list of nearly everything I googled in a week at work Rather than my posting a huge list, check out the day logs on her post Worth calling out a few: Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag? - said React upgrade then started causing some super fun errors. semantic HTML contact details - wanted to check if the [HTML_REMOVED] tag was relevant here editing host file - desperate times (and it didn't even work) Madison #3: PyCascades 2022! Another year of excellent and diverse talks across an array of subjects. Talks from some well known folks (Thursday Bram, Jay Miller) as well as first time speakers (Joseph Riddle, Isaac Na) PSF's DE&I Panel is doing a meet & greet, and they have a survey they'd like Python community members to fill out. Socials Friday & Saturday night, sprints on Sunday. Tickets are still available! Brian #4: Strict Python function parameters Seth Michael Larson We have keyword only parameters def process_data(data, *, encoding="ascii"): ... notice the * encoding has to be a keyword argument, cannot be positional. We have position only parameters: def process_data(data, /, encoding="ascii"): ... notice the / data has to be positional, cannot be passed in as a keyword argument Combine the two: def process_data(data, /, *, encoding="ascii"): ... Now data has to be positional, and encoding has to be a keyword, if present. This way a function really can only be called as intended and all uses of the function will be consistent. This is a good thing. There are many benefits, including empowering library authors to make changes without weird behaviors cropping up in user code. Commentary: extra syntax may be confusing for some new users. For a lot of library API entry points, I think this makes a lot of sense. Michael #5: mureq - vendored requests mureq is a single-file, zero-dependency alternative to python-requests Intended to be vendored in-tree by Linux systems software and other lightweight applications. Doesn't support connection pooling (but neither does requests.get()). Uses much less memory Avoids supply chain attack vulnerabilities Consider my prod branch until PRs #2 and #3 are merged. Madison #6: Openverse No, not Metaverse! Previously “CC Search” Search engine for openly licensed media, for free and public use/remix of content. Currently images & audio, hope to include video, text, 3D models down the line. Start your search here Extras Michael: We now have playable times in the transcript section (example). Very cool tool for building regex-es I used for the above: regex101.com Next video is out: Do you even need loops in Python? A Python short by Michael Kennedy Remember, we have full-text search Brian: pip-secure-install - from Brett Cannon Python Testing with pytest is, when I last checked, the #2 bestseller at Pragmatic so cool My Maui trip was also a work trip. Gave me time to completely re-read the book, make notes, and make last minute changes. Changes went in this week and tonight is my “pencils down” date. This is getting real, folks. Thanks to everyone for buying beta copies and supporting the re-write. Madison: spd.watch - new police accountability/information tool for the Seattle area Shoutout to just (mentioned in Ep 242) ghcr.io - free docker image hosting for open source projects, easy integration with GitHub Actions Joke: via Josh Thurston How did the hacker get away from the police? He just ransomware. That joke makes me WannaCry… Where do you find a hacker? In decrypt.
In the preface of "Python Testing with pytest" I list some reasons to use pytest, under a section called "why pytest?". Someone asked me recently, a different but related question "why NOT unittest?". unittest is an xUnit style framework. For me, xUnit style frameworks are fatally flawed for software testing. That's what this episode is about, my opinion of * "Why NOT unittest?", or more broadly, * "What are the fatal flaws of xUnit?"
Watch the live stream: Watch on YouTube About the show Sponsored by Shortcut - Get started at shortcut.com/pythonbytes Special guest: The Anthony Shaw Michael #0: It's episode 2^8 (nearly 5 years of podcasting) Brian #1: Where does all the effort go?: Looking at Python core developer activity Łukasz Langa A look into CPython repository history and PR data Also, nice example of datasette in action and lots of SQL queries. The data, as well as the process, is open for anyone to look at. Cool that the process was listed in the article, including helper scripts used. Timeframe for data is since Feb 10, 2017, when source moved to GitHub, through Oct 9, 2021. However, some queries in the article are tighter than that. Queries Files involved in PRs since 1/1/20 top is ceval.c with 259 merged PRs Contributors by number of merged PRs lots of familiar names in the top 50, along with some bots it'd be fun to talk with someone about the bots used to help the Python project nice note: “Clearly, it pays to be a bot … or a release manager since this naturally causes you to make a lot of commits. But Victor Stinner and Serhiy Storchaka are neither of these things and still generate amazing amounts of activity. Kudos! In any case, this is no competition but it was still interesting to see who makes all these recent changes.” Who contributed where? Neat. There's a self reported Experts Index in the very nice Python Developer's Guide. But some libraries don't have anyone listed. The data does though. Łukasz generated a top-5 list for each file. Contributing to some file and have a question. These folks may be able to help. Averages for PR activity core developer authoring and merging their own PR takes on average ~7 days (std dev ±41.96 days); core developer authoring a PR which was merged by somebody else takes on average 20.12 days (std dev ±77.36 days); community member-authored PRs get merged on average after 19.51 days (std dev ±81.74 days). Interesting note on those std deviations: “Well, if we were a company selling code review services, this standard deviation value would be an alarmingly large result. But in our situation which is almost entirely volunteer-driven, the goal of my analysis is to just observe and record data. The large standard deviation reflects the large amount of variation but isn't necessarily something to worry about. We could do better with more funding but fundamentally our biggest priority is keeping CPython stable. Certain care with integrating changes is required. Erring on the side of caution seems like a wise thing to do.” More questions to be asked, especially from the issue tracker Which libraries require most maintenance? Michael #2: Why you shouldn't invoke setup.py directly By Paul Ganssle (from Talk Python #271: Unlock the mysteries of time, Python's datetime that is!) In response to conversation in Talk Python's cibuildwheel episode? For a long time, setuptools and distutils were the only game in town when it came to creating Python packages You write a setup.py file that invokes the setup() method, you get a Makefile-like interface exposed by invoking python setup.py [HTML_REMOVED] The last few years all direct invocations of setup.py are effectively deprecated in favor of invocations via purpose-built and/or standards-based CLI tools like pip, build and tox. In Python 2.0, the distutils module was introduced as a standard way to convert Python source code into *nix distro packages One major problem with this approach, though, is that every Python package must use distutils and only distutils — there was no standard way for a package author to make it clear that you need other packages in order to build or test your package. => Setuptools Works, but sometimes you need requirements before the install (see cython example) A build backend is something like setuptools or flit, which is a library that knows how to take a source tree and turn it into a distributable artifact — a source distribution or a wheel. A build frontend is something like pip or build, which is a program (usually a CLI tool) that orchestrates the build environment and invokes the build backend In this taxonomy, setuptools has historically been both a backend and a frontend - that said, setuptools is a terrible frontend. It does not implement PEP 517 or PEP 518's requirements for build frontends Why am I not seeing deprecation warnings? Use build package. Also can be replaced by tox, nox or even a Makefile Probably should just check out the summary table. Anthony #3: OpenTelemetry is going stable soon Cloud Native Computing Foundation project for cross-language event tracing, performance tracing, logging and sampling for distributed applications. Engineers from Microsoft, Amazon, Splunk, Google, Elastic, New Relic and others working on standards and specification. Formed through a merger of the OpenTracing and OpenCensus projects. Python SDK supports instrumentation of lots of frameworks, like Flask, Django, FastAPI (ASGI), and ORMs like SQLalchemy, or templating engines. All data can then be exported onto various platforms : NewRelic, Prometheus, Jaeger, DataDog, Azure Monitor, Google Cloud Monitoring. If you want to get started and play around, checkout the rich console exporter I submitted recently. Brian #4: Understanding all of Python, through its builtins Tushar Sadhwani I really enjoyed the discussion before he actually got to the builtins. LEGB rule defines the order of scopes in which variables are looked up in Python. Local, Enclosing (nonlocal), Global, Builtin Understanding LEGB is a good thing to do for Python beginners or advanced beginners. Takes a lot of the mystery away. Also that all the builtins are in one The rest is a quick scan through the entire list. It's not detailed everywhere, but pulls over scenic viewpoints at regular intervals to discuss interesting parts of builtins. Grouped reasonably. Not alphabetical Constants: There's exactly 5 constants: True, False, None, Ellipsis, and NotImplemented. globals and locals: Where everything is stored bytearray and memoryview: Better byte interfaces bin, hex, oct, ord, chr and ascii: Basic conversions … Well, it's a really long article, so I suggest jumping around and reading a section or two, or three. Luckily there's a nice TOC at the top. Michael #5: FastAPI, Dask, and more Python goodies win best open source titles Things that stood out to me FastAPI Dask Windows Terminal minikube - Kubernetes cluster on your PC OBS Studio Anthony #6: Notes From the Meeting On Python GIL Removal Between Python Core and Sam Gross Following on from last week's share on the “nogil” branch by Sam Gross, the Core Dev sprint included an interview. Targeted to 3.9 (alpha 3!), needs to at least be updated to 3.9.7. Nogil: Replaces pymalloc with mimalloc for thread safety Ties objects to the thread that created them witha. non-atomic local reference count within the owner thread Allows for (slower) reference counting from other threads. Immortalized some objects so that references never get inc/dec'ed like True, False, None, etc. Deferred reference counting Adjusts the GC to wait for all threads to pause at a safe point, doesn't wait for I/O blocked threads and constructs a list of objects to deallocate using mimalloc Relocates the MRO to a thread local (instead of process-local) to avoid contention on ref counting Modifies the builtin collections to be thread-safe (lists, dictionaries, etc,) since they could be shared across threads. IMHO, biggest thing to happen to Python in 5 years. Encouragingly, Sam was invited to be a Core Dev and Lukasz will mentor him! Extras Michael Python Developers Survey 2021 is open More PyPI CLI updates bump2version via Bahram Aghaei (youtube comment) Was there a bee stuck in Brian's mic last time? Brian PyCon US 2022 CFP is open until Dec 20 Python Testing with pytest, 2nd edition, Beta 7.0 All chapters now there. (Final chapter was “Advanced Parametrization”) It's in technical review phase now. If reading, please skip ahead to the chapter you really care about and submit errata if you find anything confusing. Joke:
In this episode Julian has a conversation with Andrew Knight, the Automation Panda, about his journey in the Python space. Over the years, Andy has worked his way beyond being in the developer job he'd always wanted, to being a prominent figure in the Python Testing space.Andy shares the story of how he started in the industry and what his first big hurdle was. There are just so many mindset lessons and tips he used throughout his journey that this is an episode you simply have to listen to.As Julian and Andy are mates off-microphone, the conversation is light, leads to quite a few laughs and is one of our lengthier episodes (I don't regret a second! - Julian).Enjoy and as always, give us a like/recommendation and please share with anyone that might find this useful.Andy's Twitter: https://twitter.com/AutomationPandaAndy's Blog: https://automationpanda.com/Test Automation University: https://testautomationu.applitools.com/instructors/andrew_knight.htmlHollow Knight: https://www.nintendo.com/games/detail/hollow-knight-switch/
An overview of the pytest flags that help with debugging. From Chapter 13, Debugging Test Failures, of Python Testing with pytest, 2nd edition (https://pythontest.com/pytest-book/). pytest includes quite a few command-line flags that are useful for debugging. We talk about thes flags in this episode. Flags for selecting which tests to run, in which order, and when to stop: * -lf / --last-failed: Runs just the tests that failed last. * -ff / --failed-failed: Runs all the tests, starting with the last failed. * -x / --exitfirst: Stops the tests session afterEd: after?Author: yep the first failure. * --maxfail=num: Stops the tests after num failures. * -nf / --new-first: Runs all the tests, ordered by file modification time. * --sw / --stepwise: Stops the tests at the first failure. Starts the tests at the last failure next time. * --sw-skip / --stepwise-skip: Same as --sw, but skips the first failure. Flags to control pytest output: * -v / --verbose Displays all the test names, passing or failing. * --tb=[auto/long/short/line/native/no] Controls the traceback style. * -l / --showlocals Displays local variables alongside the stacktrace. Flags to start a command-line debugger: * --pdb Starts an interactive debugging session at the point of failure. * --trace Starts the pdb source-code debugger immediately when running each test. * --pdbcls Uses alternatives to pdb, such as IPython's debugger with –-pdbcls=IPython.terminal.debugger:TerminalPdb. This list is also found in Chapter 13 of Python Testing with pytest, 2nd edition (https://pythontest.com/pytest-book/). The chapter is "Debugging Test Failures" and covers way more than just debug flags, while walking through debugging 2 test failures.
Watch the live stream: Watch on YouTube About the show Sponsored by us: Check out the courses over at Talk Python And Brian's book too! Special guest: Nick Muoh Brain #1: ormar : an async mini ORM for Python, with support for Postgres, MySQL, and SQLite. suggested by John Hagen From John: “It's a really cool ORM that combines Pydantic models and SQL models into a single definition. What is great about this, is it can be used to reduce repetitive duplication between Models for an ORM and the Pydantic Models that FastAPI needs to describe serialization. … If you have very pure-data heavy abstractions where your input and outputs through the API are roughly equivalent to your database, this helps you avoid needing to duplicate tons of SQLAlchemy classes and Pydantic that look identical and now you need to keep them in sync (DRY issue).” Michael #2: No module named via Garett Dunn Website: nomodulenamed.com Get an error like Python Error: No module named dateutil, maybe you need pip install python_dateutil (reference) Nick #3: JupyterLite Jeremy Tuloup JupyterLite is a JupyterLab distribution that runs entirely in the browser built from the ground-up using JupyterLab components and extensions. Python kernel backed by Pyodide running in a Web Worker Kernels include Python 3.8 (pyolite implementation) Javascript P5.js Data is written to in-browser storage Data doesn't leave the browser unless you are using extensions or use browser's fetch API Brian #4: Lot of plots Dylan Castillo Side by side comparison of plots. with: pandas, matplotlib, seaborn, plotly.express plotting: line, grouped bars, stacked bars, area, pie/donut, histogram, scatter, and box Many plotting articles talk about cool stuff you can do with a particular library. This is nice in that they all can do these things, so you can see the output of each and compare see the code that goes into making each, and see what style of api you might like to work with Michael #5: Monty, Mongo tinified. MongoDB implemented in Python Monty, Mongo tinified. MongoDB implemented in Python Inspired by TinyDB and it's extension TinyMongo A pure Python-implemented database that looks and works like MongoDB.
Matt Harrison, author of many Python books, is putting together a course, Effective Book Authoring, to help other people write and publish books. As part of this course, he's including interviews with people who have already written books, including me. This is that interview. We discuss: * Why I wrote "Python Testing with pytest" * Self publishing vs working with a publisher * The writing, editing, and publishing process * Writing format * Book promotion * Advice to other writers Special Guest: Matt Harrison.
Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest Michael #1: Under the hood of calling C/C++ from Python Basics first: what C compiles to? Each operating system features some exact format to work with. Among the most popular ones are: ELF (Executable and Linkable Format), used by most of Linux distros PE (Portable Executable), used by Windows Mach-O (Mach object), used by Apple products We also need to make our library visible to our programs. An easiest way to do so is to copy it to /usr/lib/ - default system-wide directory for libraries. Maybe put it in system / system32 on Windows? ctypes: the simplest way With the shared object compiled, we are ready to call it. Consider ctypes to be the easiest way to execute some C code, because: it’s included in the standard library, writing a wrapper uses plain Python. lib = ctypes.CDLL(f'/usr/lib/libdullmath.so') lib.get_pi For C: You need to be clear about the calling convention (extern “C” for example) Now we can load libraries at runtime, but we are still missing the way to generate correct caller ABI to use external C libraries. Do deal with it, libffi was created. Libffi is a portable C library, designed for implementing FFI tools, hence the name. Given structs and functions definitions, it calculates an ABI of function calls at runtime. A mature approach to improve in this area is to allow libraries to introduce themselves. We can oblige every library to define a function named entry_point, which will return metadata about functions it contains. Final destination: C/C++ extensions and Python/C API CPython provides a similar API for implementing C-based extensions: “Extending and Embedding the Python Interpreter”. // NOTE: entry point function has dynamic name PyInit_[HTML_REMOVED] PyMODINIT_FUNC PyInit_mymath(void) { return PyModule_Create(&mymathmodule); } The main difference is that we have to wrap initial C functions with Python-specific ones. CPython interpreter uses its own PyObject type internally rather than raw int, char*, and so on, and we need the wrappers to perform the conversion. Cython, Boost.Python, pybind11 and all all all The main challenge of writing pure C extensions is a massive amount of boilerplate that needs to be written. Mainly this boilerplate is related to wrapping and unwrapping PyObject. It becomes especially hard if a module introduces its own classes (object types). To solve this issue, a plethora of different tools was created. All of them introduce a certain way to generate wrapping boilerplate automatically. They also provide easy access to C++ code and advanced tools for the compilation of extensions. Examples aiohttp - asyncio web framework that uses Cython for HTTP parsing, uvloop - event loop that is wrapping libuv, fully written in Cython, httptools - bindings to nodejs HTTP parser, also fully written in Cython (a lot of other big projects like sanic or uvicorn use httptools). Cecil #2: ugit: DIY Git in Python Michael #3: Things I Learned to Become a Senior Software Engineer by Niel Kakkar Growing using different ladders of abstraction Entering my second year, I had all the basics in place. I did figure out something insightful. I’m working inside the software development lifecycle, but this lifecycle is part of a bigger lifecycle: the product and infrastructure development lifecycle. Learning what people around me are doing Since we’re not in a closed system, it makes sense to better understand the job of the product managers, the sales people, and the analysts. Product managers are the best source for this. They know how the business makes money, who are the clients, and what do clients need. Learning good habits of mind Thinking well: Diving into cog sci, one output was a framework for critical thinking. It’s compounding, and compounding is powerful. Strategies for making day-to-day more effective: The other side of the coin is habits that allow you to think well. It starts with noticing little irritations during the day, inefficiencies in meetings, and then figuring out strategies to avoid them. Some good habits I’ve noticed: Never leave a meeting without making the decision / having a next action Decide who is going to get it done. Things without an owner rarely get done. Document design decisions made during a project Acquiring new tools for thought & mental models New tools for thought are related to thinking well, but more specific to software engineering. For example, I was recently struggling with a domain with lots of complex business logic. Edge cases were the norm, and we wanted to design a system that handles this cleanly. That’s when I read about Domain Driven Design Protect your slack When I say slack, I don’t mean the company, but the adjective. One thing that gives me high output and productivity gains is to “slow down”. Want to get more done? Slow down. When there is slack, you get a chance to experiment, learn, and think things through. This means you get enough time to get things done. When there is no slack, deadlines are tight, and all your focus goes into getting shit done. Ask Questions Q: What is a package? A: It’s code wrapped together that can be installed on a system. Q: Why do I need packages? A: They give a consistent way of getting all the files you need in the right place. Without them, things are easy to mess up. You need to ensure every file is where it’s supposed to be, the system paths are set up, and dependent packages are available. Q: How do packages differ from applications I can install on my system? A: It’s a very similar idea! Windows installer is like a package manager that helps install applications. Similarly, DPKG and rpm packages are like .exes that you can install on Linux systems, with the help of apt and yum package managers, which are like the windows installers. Force multipliers One sprint I didn’t get much done myself. I wrote very limited code. Instead, I co-ordinated which changes should go out when (it was a complicated sprint), tested they worked well, did lots of code reviews, made alternate design suggestions, and pair-programmed wherever I could to get things un-stuck. We got everything done, and in this case, zooming out helped make decisions for PRs easier. It was one of our highest velocity sprints. Embrace fear: I’ve learned to embrace this feeling. It excites me. It’s information about what I’m going to learn. I’ve taken it so far that I’ve started tracking it in my human log - “Did I feel fear this week?” If the answer is no too many weeks in a row, I’ve gotten too comfortable. Super powers Getting into the source code when documentation isn’t enough Quest: Reading open source code. Quickly build a mental model for the code you’re looking at Quest: Reading open source code. Embracing fear Quest: Build a side project. Confidence to express ignorance Quest: Overcome the first gotcha with growing. Cecil #4: Build tech skills for space exploration Michael #5: Profiling Django Views by Farhan Azmi We know we need to profile our code Many Python profiling tools exist, but this article will limit only to the most used tools: cProfile and django-silk . The two tools mainly profile in regards to function calls and execution time. To incorporate cProfile to Django views, we can write our own middleware that captures the profiling on every request sent to our Django views. Thankfully, there exists a simpler solution: django-cprofile-middleware. It is a simple profiling middleware created by a Github user omarish. To profile this view with the installed middleware, we can just append prof parameter to the end of the URL, i.e. http://localhost:8000/api/auth/users/availability/?username=[HTML_REMOVED]&email=[HTML_REMOVED]&prof We can visualize the profile result further with Python profiler visualizing library, such as SnakeViz. Just add &download to the request. the profile result could not show which database query that brings performance hit. This is needed especially when our application is centered around database (SQL) queries: That’s where django-silk comes in. Add as middleware: Silk will automatically intercept requests we make to our views and the UI can be accessed from the path /silk/ . Dive into a request to see all the headers/form/etc + DB query and perf. Cecil #6: Send an SMS message with Azure Communication Services Extras: Michael: Was on Real Python podcast Cecil: https://studentambassadors.microsoft.com/ Joke: Dependencies
Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest Brian #1: How to be helpful online Ned Batchelder When answering questions. Lots of great advice. We’ll focus on just a few here. Answer the question first. There may be other problems with their code that they are not asking about that you want to point out. But keep that for after you’ve helped them and built up trust. No third rails. “It should be OK for someone to ask for help with a program using sockets, and not have to defend using sockets, especially if the specific question has nothing to do with sockets.” Same for pickle, threads, globals, singletons, etc. Don’t let your strong opinions derail the conversation. The goal is to help people. Strong reactions can make the asker feel attacked. No dog-piling. Meet their level. “Try to determine what they know, and give them a reasonable next step, not the ultimate solution. A suboptimal solution they understand is better than a gold standard they can’t make use of.” Say yes. Avoid absolutes. Step back. Take some blame. Use more words. “IRC and other online mediums encourage quick short responses, which are exactly the kinds of responses that will be easy to misinterpret. Try to use more words, especially encouraging optimistic words.” Understand your motivations. Humility. Make connections. Finally: It’s hard. All of Ned’s advice is great. Good meditations for when you read a question and your mouth drops open and your eyes stare in shock. Michael #2: blackcellmagic IPython magic command to format python code in cell using black. Has a great animated gif ;) Just do: %load_ext blackcellmagic Then in any cell %%black and magic! Accepts “arguments” like %%black -l 79 Tobin Jones has been kind enough to develop a NPM package over blackcellmagic to format all cells at once which can be found here. But it’s archived so no idea whether it’s current. Brian #3: Test smarter, not harder Luke Plant There’s lots of great advice in here, but I want to highlight two parts that are often overlooked. “Write your test code with the functions/methods/classes you wish existed, not the ones you’ve been given.” “If the API you want to use doesn’t exist yet, you still use it, and then make it exist.” This is huge. People tend to think like this while coding, but forget to do it while testing. Also. Your tests are often the first client for your API, so if the API in question is under your control and you need an easier API for testing, consider adding it to the real API. If it’s easier for testing, it may be easier for other clients of the API as well. “Only write necessary tests — specifically, tests whose estimated value is greater than their estimated cost. This is a hard judgement call, of course, but it does mean that at least some of the time you should be saying “it’s not worth it”.” Michael #4: US: The Greatest Package in the World by Jeremy Carbaugh A package for easily working with US and state metadata: all US states and territories postal abbreviations Associated Press style abbreviations FIPS codes capitals years of statehood time zones phonetic state name lookup is contiguous or continental URLs to shapefiles for state, census, congressional districts, counties, and census tracts The state lookup method allows matching by FIPS code, abbreviation, and name Even a CLI: $ states md Brian #5: Think Like A Coder Part of TED-Ed “… a 10-episode series that will challenge viewers with programming puzzles as the main characters— a girl and her robot companion— attempt to save a world that has been plunged into turmoil.” Although, I only count 9 episodes, I was 4 episodes in and hooked. Main cool thing, I think, is introducing terms and topics so they will be familiar when someone really does start coding: loops, for loops, until loops, while loops conditionals variables path logic permutations searches tables recursion Big O Also highly recommended for getting excited about coding: Girls Who Code: Learn to Code and Change the World TED-Ed has tons of other cool series on lots of subjects. CodeCombat Michael #6: Costs of running a Python web app for 55k monthly users How much does running a web app in production actually cost? KeepTheScore is an online software for scorekeeping. Create your own scoreboard for up to 150 players and start tracking points. It's mostly free and requires no user account. Keepthescore.co is a Python flask application running on DigitalOcean and Firebase. It currently has around 55k unique visitors per month, per day it’s around 3.4k. Servers and database on DigitalOcean: Costs per month: $95, the servers are oversized for the load they’re currently seeing. Amazon Web Services: Costs per month: $60, use a reporting tool called Metabase to generate insights and reports from the database Google Cloud, costs per month: $1.32, for Firebase DNS hosting, costs per month: $5 Disqus, costs per month: $10 Is it worth it? Is there revenue? In total that’s around $171 USD per month. If you’re running a company with employees that would be peanuts, but in this case the cost is being borne by a single indie-developer out of his own pocket. The bigger issue is that on the revenue side there’s a big fat zero. This is the reason why we are currently working on monetization. Some Talk Python stats: Maybe 40k monthly visitors, but oh, the podcast clients 3M requests / month just RSS, resulting in 320 GB / mo of XML traffic. We run on two prod servers: $10 & $5 as well as a dedicated MongoDB server @ $10. Total $25/mo. On the other hand, Talk Python Training's AWS bill last month was over $1,000 USD. You can hear a bunch about this on Talk Python 215. Joke: From twitter, originally from Netlify: "Oh no! We lost the hackers! Where did they go?" "I don't know! They just ransomware!” Number of days since I have encountered an array index error: -1.
Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest Michael #1: micropython updated via Matt Trentini v1.13 is packed with features and bugfixes including solid asyncio support and tasty BLE improvements. Heck, we've even got the walrus operator. a new implementation of the uasyncio module which aims to be more compatible with CPython's asyncio module. The main change is to use a Task object for each coroutine, allowing more flexibility to queue tasks in various places, eg the main run loop, tasks waiting on events, locks or other tasks. It no longer requires pre-allocating a fixed queue size for the main run loop. Most code in this repository is now auto-formatted using uncrustify for C code and Black for Python code. BlueKitchen BTstack bindings have been added for the ubluetooth module, as an optional alternative to the NimBLE stack. The unix port can now be built with BLE support using these bindings Other Bluetooth additions include: new events for service/characteristic/ descriptor discovery complete; new events for read done and indicate acknowledgement; and support for active scanning in BLE.gap_scan(). PEP 526 has been (Walrus) There has been an important bug fix when importing ARM machine code from an .mpy file: the system now correctly tracks the executable memory allocated to the machine code so this memory is not reclaimed by the garbage collector. For testing, a multi-instance test runner has been added (see tests/run-multitests.py) which allows running a synchronised test across two or more MicroPython targets. There are breaking changes First release since Dec 19, 2019 Brian #2: respx: A utility for mocking out the Python HTTPX library When using requests, you can mock it with responses. When using httpx, mock with respx. Quick start: import httpx import respx @respx.mock def test_something(): request = respx.post("https://foo.bar/baz/", status_code=201) response = httpx.post("https://foo.bar/baz/") assert request.called assert response.status_code == 201 Documentation includes examples of using respx with both pytest and unittest, including how to set up mocked_api fixtures for pytest. There’s call statistics you can assert on. Ability to raise exceptions, return non-200 status codes, set custom return content. Content can be generated in a callback method. JSON content can be returned Tons of nice options to help test your httpx based application. Michael #3: GetPy - A Vectorized Python Dict/Set The goal of GetPy is to provide the highest performance python dict/set that integrates into the python scientific ecosystem. GetPy is a thin binding to the Parallel Hashmap (https://github.com/greg7mdp/parallel-hashmap.git) which is the current state of the art unordered map/set with minimal memory overhead and fast runtime speed. The binding layer is supported by PyBind11 (https://github.com/pybind/pybind11.git) The gp.Dict and gp.Set objects are designed to maintain a similar interface to the corresponding standard python objects. Simple example: - import getpy as gp key_type = np.dtype('u8') value_type = np.dtype('u8') keys = np.random.randint(1, 1000, size=10**2, dtype=key_type) values = np.random.randint(1, 1000, size=10**2, dtype=value_type) gp_dict = gp.Dict(key_type, value_type) gp_dict[keys] = values Brian #4: isort and black now play nice together easily Contributed by John Hagen isort “sorts your imports, so you don’t have to” black reformats all of your code to a consistent code style, including import statements There is a config page on black documentation that shows how to set isort to be compatible with black. It also shows how to make flake8 and pylint play nice with black, but they are less complicated. Now, however, with isort 5 introduction of built in profiles, you can just use isort --``profile black . and the profile sets everything for you. There’s a profile page for isort that describes all that it does. Other profiles include: django, pycharm, google, open_stack, plone, attrs, hug And as always, you can configure your own with config files. Michael #5: Scientists rename human genes to stop Microsoft Excel from misreading them as dates Via Chris Moffitt There are tens of thousands of genes in the human genome Each gene is given a name and alphanumeric code, known as a symbol, which scientists use to coordinate research. Over the past year or so, some 27 human genes have been renamed, all because Microsoft Excel kept misreading their symbols as dates. Excel is regularly used by scientists to track their work and even conduct clinical trials. But its default settings were designed with more mundane applications in mind, so when a user inputs a gene’s alphanumeric symbol into a spreadsheet, like MARCH1 — short for “Membrane Associated Ring-CH-Type Finger 1” — Excel converts that into a date: 1-Mar. One study from 2016 examined genetic data shared alongside 3,597 published papers and found that roughly one-fifth had been affected by Excel errors. See 12 of the Biggest Spreadsheet Fails in History for more examples: https://blogs.oracle.com/smb/10-of-the-costliest-spreadsheet-boo-boos-in-history The scientific body in charge of standardizing the names of genes, the HUGO Gene Nomenclature Committee, published new guidelines for gene naming. From now on human genes and the proteins they expressed will be named with one eye on Excel’s auto-formatting. Check out the Excel to Python course and webcast to escape this. Brian #6: Never Run ‘python’ In Your Downloads Folder by Glyph This is really a nice, short tutorial on how sys.path is populated, why you should care, and why you need to make sure it’s only trusted locations. “downloads” is definitely not trusted. So never, ever, ever run python from the downloads directory, even with python -m something, as that adds the download dir to the include path. Example includes a demonstration of malicious js code that downloads a fake pip.py to your downloads folder, so when you call python -m pip install ./legit_package.whl you get the fake pip. Further examples show how you need to be vigilant to check your dot files for weird PYTHONPATH extensions and additions. Extras: Michael: We recently passed 5,000,000 downloads of the audio files over at Python Bytes and are the 130th most popular tech podcast in the world. Thank you everyone! Got a new LinkSys WiFi 6 mesh router, and wow, highly recommended. Joke Are you a real programmer? Check with XKCD to find out.
See the full show notes for this episode on the website at pythonbytes.fm/137.
GUEST BIO: Brian Okken is a lead software engineer for Rohde & Schwarz. He is also the author of “Python Testing with pytest” from Pragmatic, host of the “Test & Code” Podcast and Co-host of the “Python Bytes” Podcast and has spoken at PNSQC and PyCon US. EPISODE DESCRIPTION: My guest on today’s show is Brian Okken. He is currently the lead software engineer for Rohde & Schwarz. His background is in R&D, testing and measurement. When it comes to programming languages, he is something of a Python expert. Brian is the author of “Python Testing with pytest” and the host of the very popular “Test & Code” podcast, he also co-hosts “Python Bytes”. Brian is passionate about sharing his knowledge. So, he teaches and regularly speaks publicly at conferences like PyCon and PNSQC. KEY TAKEAWAYS: (1.00) – So Brian, can you expand on that brief introduction and tell us a little bit more about yourself? Brian explains that he still describes himself as a software engineer. But, in reality, for the past 10 to 15 years, he has been mostly involved with automated testing. (1.21) – How did you get into automated testing? Brian explains that it was not a planned transition. It was a requirement within the test equipment industry. Those that work in that field spend a lot of time carrying out automated and regression testing on the code and instruments. (2.10) – Can you please share a unique career tip with the I.T. career audience? Brian’s key piece of advice is to align yourself with the goals of whoever you are working for. He also advises developers to know their value and understand what it is that they contribute to the companies they work for. Once you know that, you are in a position to make sure that you more than cover the cost of your salary. Periodically asking yourself – If this was my money, would I be happy to continue to pay my salary? is a good habit to get into. (3.21) – Can you tell us about your worst career moment? And what you learned from that experience. Brian explains that one of the things he enjoys doing is honing processes, so that he can streamline the work, as much as possible. On one project he realized that if he could automate the byte and the register settings from an FPGA to the software he would save the team a lot of time and hassle. So, he set about working out how to do this. However, he did not tell anyone, including his manager, that he had taken on this extra task. Unfortunately, he got sucked in and ended up spending too much time on this side project. Naturally, his output fell, which made it look like he was not contributing to the team, as he should. Naturally, his manager was not happy. He felt that Brian was not doing the work he had been asked to do. On the other hand, Brian was disappointed and frustrated because nobody seemed to appreciate the importance of what he was trying to achieve. All in all it ended up being quite a negative situation. Brian’s advice is not to forget about process improvement completely, because t is important. But, he said that once it starts to take up more than 10% of your time, you need to let your manager knows what you are trying to achieve and how much time it is taking up. (5.11) – Phil asks Brian what his best career moment was. The highlight of Brian’s career, so far, has been his involvement in pytest and publishing his book. It was really cool getting it published. But, Brian also found that writing the book honed and deepened his skills. (5.24) – So, has that been beneficial for your career? Brian agrees that it has. While writing the book he found himself consulting and working with the core contributors. The writing process made him network more. (6.58) – Can you tell us what excites you about the future of the IT industry and career? Brian says there are so many things that excite him that it is hard to pick one thing. But, it is probably the way in which the industry is changing how it is teaching the next generation of engineers. (7.43) – Is there a particular area that interests you, technologies you feel have a real future? Brian thinks the way in which schools are finding ways to teach programming at an earlier age is exciting. However, Brian would like to see the question - How do you know it will work and continue to work? being asked and answered more in educational settings. Developers need to have a better understanding of how things work to be able to design and build more robust applications and systems. (8.44) Phil comments that, in the UK, that is certainly still an issue. Many of the degree courses leave the subject of testing right to the end of the course and the subject is rarely covered in much depth. (9.33) – What first attracted you to a career in IT, Brian? As a child, Brian had a combination games system. It had built-in games but you could also type in some simple programs to create new games like Lunar Lander. Of course, it did not work right away, so you had to figure out where you had gone wrong. When he got it working, he went back and tweaked it, for example by trying to increase acceleration. That is when he got the programming bug. It was an experience that stayed with him. He entered college as a fine art major, but switched to computer science at university. (10.50) Phil asks Brian to clarify why he made the decision to switch. Brian explains that there was a financial element to doing so. He realized that he would have less difficulty in paying back his student loan if he were able to find work in the IT field. (11.10 ) – What is the best career advice you have ever received? Brian uncovered a great piece of career advice while reading a book called Team Geek: A Software Developer's Guide to Working Well with Others. After reading that book, Brian understood that he needed to be spending at least 80% of his time creating value for the company he was working for. (12.02) – If you were to begin your IT career again, right now, what would you do? Brian says that he would not dismiss the idea of a career in web design and building, which is what he did when he first started out. He learned HTML and how to work with Perl, but veered away from building sites. At the time, he just assumed that most websites would end up being auto-built. Today, he understands that he may have missed out a bit as a result of that decision. So, now, he is learning PHP and getting into building the Python version of websites. (13.14 ) – What are you currently focusing on in your career? Right now, Brian is focusing on broadening his reach. He likes to teach and has got a lot to share with the community. (13.46) – OK, but do you have any thoughts on writing and conference speaking? Brian, says yes. He loves speaking, despite the fact he still finds doing it at conferences terrifying. But, he is a bit of a homebody and very much a family person, so he is not that keen on travelling. Despite this, he thinks he will end up travelling and speaking more in the near future. (14.25) – What is the number one non-technical skill that has helped you the most in your IT career? Brian says that is listening to people and being able to empathize with them. Phil agrees with this. He has noticed that many of us are too busy thinking about what we are going to say to be able to really listen to the other person. Brian says it is all too easy not to listen properly. He knows it is something he still needs to work on, something he discovered while listening to his own podcasts. He picked up on the fact that sometimes he was asking questions that his interviewee had already answered, which was a sure sign that he was not listening properly. (15.19) – Phil asks Brian to share a final piece of career advice with the audience. Brian says he wants to encourage people to teach. The act of writing things down or trying to explain them to someone else makes everything clearer in your own mind. Plus, it ensures that you get feedback from others, which enables you to recognize when you are wrong and learn from it. He is particularly keen to see more IT professionals writing personal blogs. BEST MOMENTS: (2.34 ) BRIAN – "Align yourself with the goals of whoever you're working for." (2.46 ) BRIAN – “Always try to be more valuable than the sticker price of your salary. " (5.49 ) BRIAN – "The process of writing the book made me an expert. " (14.30) BRIAN – "Learn how to listen to people. Really listen to their answers and empathize." ( 15.51) PHIL – "I think getting your message out there and telling people what you do and what you've learned is valuable " CONTACT BRIAN: Twitter: https://twitter.com/brianokken @brianokken LinkedIn: https://www.linkedin.com/in/okken Blog: https://pythontesting.net/ Book: https://amzn.to/2QnzvUv Podcast: https://pythonbytes.fm/ Podcast: https://testandcode.com/
What happens when 100% test code coverage just isn't enough. In this episode, we talk with Mahmoud Hashemi about glom, a very cool project in itself, but a project that needs more coverage than 100%. This problem affects lots of projects that use higher level programming constructs, like domain specific languages (DSLs), sub languages mini languages, compilers, and db query languages. Also covered: * awesome Python applications * versioning: 0-ver vs calver vs semver Special Guest: Mahmoud Hashemi.
There are lots of ways to up your skills. Of course, I'm a big fan of learning through reading books, such as upping your testing skills by reading Python Testing with pytest. And then there are online learning systems and MOOCs. At the other end of the spectrum is a full blown university degree. One option kind of in the middle is continuing education programs available through some universities, such as University of Washington. To discuss this option with me in more depth, we've got Andrew Hoover, Senior Director, Program Strategy, University of Washington Continuum College Special Guest: Andrew Hoover.
Interview with Sam Van Oort about pyresttest (https://github.com/svanoort/pyresttest), "A REST testing and API microbenchmarking tool" pyresttest A question in the Test & Code Slack channel (http://pythontesting.net/slack) was raised about testing REST APIs. There were answers such as pytest + requests, of course, but there was also a mention of pyresttest, https://github.com/svanoort/pyresttest (https://github.com/svanoort/pyresttest), which I hadn't heard of. I checked out the github repo, and was struck by how user friendly the user facing test definitions were. So I contacted the developer, Sam Van Oort, and asked him to come on the show and tell me about this tool and why he developed it. Here's the "What is it?" section from the pyresttest README: A REST testing and API microbenchmarking tool Tests are defined in basic YAML or JSON config files, no code needed Minimal dependencies (pycurl, pyyaml, optionally future), making it easy to deploy on-server for smoketests/healthchecks Supports generate/extract/validate mechanisms to create full test scenarios Returns exit codes on failure, to slot into automated configuration management/orchestration tools (also supplies parseable logs) Logic is written and extensible in Python Support Special thanks to my wonderful Patreon supporters (http://patreon.com/testpodcast) and those who have supported the show by purchasing Python Testing with unittest, nose, pytest (http://pythontesting.net/book)
Talk Python To Me - Python conversations for passionate developers
See the full show notes for this episode on the website at talkpython.fm/45.
Intro to Harry Percival, his background and story of how he got into TDD and ended up writing a book (http://amzn.to/1SqW1t3) Comparing using unittest and pytest with applicability to testing django projects. Functional end to end testing with selenium. The django test client for middle level tests. test isolation django and isolated unit tests unit tests vs integration tests Testing done by the development team without an external QA Double loop TDD: Functional test first, then unit tests Spikes: investigations without tests Harry's experience with having a freely available web version of a book that is also intended to be sold. Update: Comment from Harry Percival on 19-Jan-2014 I might have been a bit down on unit tests vs functional tests in that "unit tests never fail comment". Not true at all, particularly as we've just been thru upgrading django on our core system, and the unit tests really saved our bacon on that one... Links Test-Driven Development with Python (http://amzn.to/1SqW1t3) Obey the Testing Goat (http://pythontesting.net/obey-the-testing-goat) - Harry's site dedicated to the book and related posts. Python Testing with unittest, nose, pytest (http://pythontesting.net/book) Gary Bernhardt's talk, Boundaries talk (http://pythontesting.net/boundaries-talk) including a discussion of "Functional Core, Imperative Shell". Video of Boundaries talk on youtube (http://pythontesting.net/boundaries-talk-youtube) Special Guest: Harry Percival.