pytest Tutorial – Part 1

At PyConDE Berlin 2019 Florian Bruhin gave a really nice session about testing with pytest, which I try to recap here.

Writing Tests

If You want to work with pytest you can install it via:

pip install pytest

When you know basic python unittest fixtures, good news ahead:

pytest is compatible and will run your old unittest classes as well, but pytest doesn’t need to have a testclass derived from some subclass.

It is sufficient to have a single python file which name starts with test_ containing a function which name also starts with test_ Continue reading “pytest Tutorial – Part 1”

Software Testing Concepts – Part 1

My Tale of Woe

When I graduated from university and had my first job as a software engineer at Harman Becker Automotive Systems GmbH I should do the parental leave cover for a colleague. He showed me his project, gave me some info e.g. contact person and went off to Canada.

Literally on the second day he was away, the phone started to ring. The OEM had a A++ blocker issue found in the software and everything pointed to the component I was now maintaining. Continue reading “Software Testing Concepts – Part 1”

Python Package parameterized

Stackoverflowing around I found this nice package

https://github.com/wolever/parameterized

Parameterized testing in Python sucks.

parameterized fixes that. For everything. Parameterized testing for nose, parameterized testing for py.test, parameterized testing for unittest.

Reading this description I had very high expectations 🙂

so let’s see if the package can hold up to it. Continue reading “Python Package parameterized”

Flask 1.1 is here!

From the flask release notes:

Returning a dict from a view function will produce a JSON response. This makes it even easier to get started building an API.

To get a minimal REST-Api all you have to do is:

from flask import Flask

app = Flask(__name__)

@app.route('/return_dict', methods=['GET'])
def return_dict():
    return {"x": "1"}


if __name__ == '__main__':
    app.run(debug=True)

Distributing your own package on PyPi – Part 2

In Distributing your own package on PyPi I wrote about my first package on PyPI. Here are some refinements aka lessons learned:

Project Description on PyPI

I wondered why the project description on PyPi was empty. Solution: You need a long_description. If You already have a README.md, you can read it into a string and use this as the description.

But you have to add long_description_content_type=’text/markdown’ as well.

from setuptools import setup

# read the contents of your README file
from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='flask_url_mapping',
    version='0.6',
    packages=['flask_url_mapping'],
    url='https://github.com/jboegeholz/flaskurls',
    download_url='https://github.com/jboegeholz/flaskurls/archive/0.2.tar.gz',
    license='MIT',
    author='Joern Boegeholz',
    author_email='boegeholz.joern@gmail.com',
    description='Django-style URL handling for Flask',
    long_description=long_description,
    long_description_content_type='text/markdown',
    install_requires=["Flask", "Flask-Login"]
)

 

Dependencies of your Package

If your package relies on the usage of other python packages you should add them to your setup.py as well via install_requires.

setup(
    name='flask_url_mapping',
    version='0.6',
    packages=['flask_url_mapping'],
    url='https://github.com/jboegeholz/flaskurls',
    download_url='https://github.com/jboegeholz/flaskurls/archive/0.2.tar.gz',
    license='MIT',
    author='Joern Boegeholz',
    author_email='boegeholz.joern@gmail.com',
    description='Django-style url handling for Flask',
    install_requires=["Flask", "Flask-Login"]
)