November 30, 2021Testing Argparse Applications - the Better WayWhen you are creating command line applications in Python, you probably heard of argparse, which is a great library for exactly doing this, and it is even included in Python’s standard library. Imagine you have created the following argparse application: <main.py> import argparse def main(): parser = argparse.ArgumentParser() parser.add_argument('--name', required=True) args = parser.parse_args() print(f'Hello {args.name}') if __name__ == '__main__': sys.exit(main()) Looks straightforward, works great, but at one point, you certainly want to add tests for it, right?...
June 11, 2021How to Bring Color Back Into tox4 and pytestWhen I first tried the pre-release of the upcoming tox rewrite, I noticed tox itself has funky new colors - which I like a lot… But what happened with the green dots for pytest'soutput? You may recall, running the old tox or pytest directly, the dots would be green… why has this changed Honestly, I am not 100% sure. But I know how to get the colors back. All you need to do is changing this line commands = pytest {posargs} in your tox....
April 24, 2021How to Test Log Output With zope.testrunnerHow to test log output with zope.testrunner? While pytest makes it very easy to work with log files via the caplog fixture, I was not aware how to test them with zope.testrunner, which is used for almost all Zope repositories. When I asked during yesterday’s Zope sprint, I got no answer. But coincidentally, I stumbled upon a broken doctest which… tests the log output of a function! So… thanks for failing… I guess :-)...
December 3, 2020What Is the Difference Between Invoking `pytest` and `python -m pytest`Yesterday, I was recommended to have a look at Shopyo - Open inventory management and Point of sales. As I am passionate about testing and CI, I always have a look at configuration files for newly discovered projects. After I cloned the repository, I tried to run the tests. So, without having a look into the documentation ( :-/ ), I created a virtual env installed the dependencies ran pytest from the root of the project … and got a ModuleNotFoundError The friendly maintainers of the projects pointed me in the right direction on how to run tests for this project:...