Configure CI for Python app in Azure Devops (Pytest, Nexus IQ, SonarQube)
Example of Azure Pipeline yaml file to configure pytest with code coverage and Nexus IQ / SonarQube scanners for Python application.
Example of Azure Pipeline yaml file to configure pytest with code coverage and Nexus IQ / SonarQube scanners for Python application.
The mighty and powerful f-strings. Well, they are only a sugar syntax on string.format, but whatever. Here I will look at one of the usage scenarios that you should not commit - taking format string from the user. Well, I had to do it in my project, so…
When we have time-expensive functionality in our fixtures, it is good to know when they are invoked and run. Although this should be intuitive, let’s test on a simple example.
In one of the recent episode of Python podcast, Toby Macey was interviewing Luciano Ramalho. I have a lot of respect for this developer as for me it is one of the last true “Pythonista’s” left in the world. During one hour he talks about his Python beginnings, writing “Fluent Python” book, and his view about new Python features. I recommend listening to the whole podcast, but here is a summary of his opinions about Python evolution.
WSGI - Web Server Gateway Interface. This is Python standard interface between web server software and web applications. The specification was created in 2003 and described in PEP 333, further updated in 2010 in PEP 3333, with backward compatibility to prepare for Python 3 changes.
It is funny that when one decides to refresh the basics of Python, watches the first video about types and is already stuck for an hour testing edge cases and wondering why? Let’s explore the bool function with empty containers.
Let’s connect MySQL database installed in Ubuntu (WSL2) with Pycharm Professional on Windows.
Recently I have started to dive into game programming a bit more. Coming from Python with Pyglet, my current choice is Godot game engine. I created a simple text-based game menu in both to see what is easier for someone without any prior experience.
Recently I dived into design patterns a little bit, to refresh a rusty knowledge. It is something we are using in Python daily, however not often realizing that. And I like reading those religious debates between programmers. One of them is the usage of Singleton in Python. Let’s see what is Pythonistas take on this beloved pattern.
The first paragraph from Python documentation about concurrency titled “Concurrent Execution” mentions a few phrases like, CPU bound, IO bound, event-driven cooperative multitasking or preemptive multitasking. In this intro post to concurrency, let’s clarify these definitions.
In pytest we can parametrize in three different ways:
This article presents a few examples of how to use parametrization in pytest using @pytest.mark.parametrize. The article starts from the basic tests, and end with the usage of ids and indirect.
The famous PEP 572, and one of the reasons Guido Van Rossum - Python BDFL - retired from decision process (stepped down as BDFL). It is called “Assignment Expressions”, and is about adding new syntax := that will allow assign to variables within an expression.
In Python, we have positional and keywords arguments. With the introduction of new syntax in PEP 570, we can specify positional-only parameters in Python function definitions. This feature is especially useful for library developers, to ensure correct usage of an API. Let’s discuss what this PEP is all about.
PEP (Python Enhancement Proposal) are describing new features, processes or other guidelines and information. They are written primarily for core CPython or other implementation developers. But actually, they are fun and interesting read for a regular developer as well. It is because the authors are really polishing the documents (standards are rigorous) and in addition to documentation, we can get to know proposed or already implemented features. Anyway, fun to read. One disadvantage, PEPs are sometimes long.
Coming from for Java world we could ask what the best way for method overloading in Python language is. There are many ways to achieve that; some are even considered an anti-patterns. Let’s through a few of them and choose the best.
Task: Define the function that takes two parameters (dictionaries as default). Without modifying original dictionaries return the new one that includes all key and value pairs however, if key repeats itself, then add values
a = {'a': 5, 'b': 1, 'c': -1, 'd': 1}
b = {'a': 1, 'b': 5, 'c': 1, 'e': 1}
solution = {'a': 6, 'b': 6, 'c': 0, 'd': 1, 'e': 1}
Task: merge and sort two ordered lists
list_a = [8, 10, 12, 44, 63, 66]
list_b = [2, 3, 20, 106, 144]
solution = [2, 3, 8, 10, 12, 20, 44, 63, 66, 106, 144]
This morning for the interviewed person we had a short algorithmic task. Given n = 5, create a list of multiplied integers:
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
My little tour on Python Web Shops is over for now. It has been an excellent chance to see what is going on in the town. I have been applying mainly for a web developer position. Below is a list of few interview questions I have got. I will answer the most interesting or ones that require more in-depth research in the next articles.
Python 3.5 brought us 4-100 times faster OrderedDict thanks to its implementation in C, before was written in Python. Python 3.6 improved a standard library dictionary, by making it use more compact representation. Now dictionary could use 20% to 25% less memory compared to Python 3.5, and the order of items was kept but as suggested it was only an implementation detail and should not be used officially (backwards compatibility). Well, in Python 3.7 it has been approved.
Which one should we use now? Standard dict or OrderedDict ?
I have had a chance to solve Codility demo test. It is available for free, and you can try it unlimited times. While I do not believe that such tests correlate to typical real-world programming tasks, they are often used as a first interview filter by some companies. Here I show a few Python variations for the solution.
After three years of using Sublime Text 3, more than one year with PyCharm (Community at home and Professional at work) should I switch to Wing IDE? It has some of the best features from previous editors. Time to compare them.
Update: Similar setup but for CircleCI 2.0 is HERE
Deploying to CircleCI as easy as creating yaml file (sometimes you even do not need it as Circle will automatically recognize structure and behavior). But usually it is better to setup at least basic configuration. The problem begins with more complicated functionality and CI documentation is minimal, or to say ‘very hacker friendly’.
My problem was how to use build-in PostgreSQL database with Python application. This is quick tip how I solved it.