Tuesday, May 01, 2018

Pytest warning: How to fix Pytest plugin warnings

If, like most of the guys I know, you use Pytest for testing, you will at some stage run into different warnings when running your tests. Mine for some reason started issuing a warning like this:
pytest_funcarg__cov: declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0.  Please remove the prefix and use the @pytest.fixture decorator instead.

Although, this did not stop the test from passing - it simply changed the colour to yellow instead of green to indicate that your tests passed successfully.

In my case, the issue was due to an outdated version of pytest-cov plugin that was installed as part of the original pytest installation. As it turns out, pytest won't upgrade it even when you upgrade your pytest version. So, you are left to not only figure out what the issue is, but how to fix it.

In most cases where similar warnings are shown, it can easily be fixed by first identifying which of the plugins is causing the issue rather than suppressing it; and attempt to upgrade it separately. This should hopefully fix it.

Again, in my case a simple command like this:
pip install --upgrade pytest-cov

helped to fix the issues and returned my test results to green.

Sunday, January 07, 2018

Sorting Python Dictionary By Values

First, I would like to say happy new year to you and hope you had a great 2017 and looking forward to a more rewarding and better year ahead. My 2017 started not very well, but ended on a high. I changed jobs. I will write about it later.

For now I just wanted to document something I hope will be useful to others as much as it has been for me.

There are times when something quite seemingly quite simple can be nothing but. In MySQL, it's simple to group by a field but didn't think I could do the same thing in Python. A quick search led to this example that I quickly adapted to fit my need. Hence this post... not only to share but to also document it just in case the original link disappears like some sites do these days.

from operator import itemgetter
from itertools import groupby
rows = [
    {'address': '5412 N CLARK', 'date': '07/01/2012'},
    {'address': '5148 N CLARK', 'date': '07/04/2012'},
    {'address': '5800 E 58TH', 'date': '07/02/2012'},
    {'address': '2122 N CLARK', 'date': '07/03/2012'},
    {'address': '5645 N RAVENSWOOD', 'date': '07/02/2012'},
    {'address': '1060 W ADDISON', 'date': '07/02/2012'},
    {'address': '4801 N BROADWAY', 'date': '07/01/2012'},
    {'address': '1039 W GRANVILLE', 'date': '07/04/2012'},
]
# Sort by the desired field first rows.sort(key=itemgetter('date')) # Iterate in groups for date, items in groupby(rows, key=itemgetter('date')): print(date) for i in items: print(' ', i)
Then: https://stackoverflow.com/questions/9198334/how-to-build-up-a-html-table-with-a-simple-for-loop-in-jinja2

Thursday, April 20, 2017

Learning R

A few years ago I was a very active Java developer and advocate. I loved it, helped to organise meetup events and even spent many nights answering questions in the now-defunct Java forum. I'm sure some old time Java developers here will still remember those days.
It used to be quite fun; I learnt a lot myself just by researching and helping people with their issues. You can't provide a solution if you haven't compiled and ran the code yourself - which is a great way to learn.
 
But sometime in 2009, I discovered Python by share chance. In one of the many forums online, someone was asking about open source anti-virus software - and if they were any good compared to paid software.
A few people suggested that Clamwin was quite good and it was open source. This got my thinking that it would be nice to see how real-world open source applications were developed.
 
Downloaded the code and studied just about every file in the project folder. That was my very first exposure to Python and it was surprisingly easy to understand the code. The C code on the other hand was bit trickier and somewhat confusing to say the least :)
This led to me learning Python and eventually getting a job as a developer using the language; and slowly using less of Java.

However, in the last 6 months or so, I have started messing about with R and I'm blown away at how quickly you can knock things together especially when it comes to data.

I will be adding more R code here as time goes on - this is mainly for me to document my progress and to share something that others can hopefully find useful.
Related Posts with Thumbnails