Code coverage in Python, or my first little challenge.

Please note that everything written below is just my personal observations, reasoning and conclusions. It may be useful to you, but do not consider it at as verified knowledge source, as information here may be incomplete or mistaken.

I got tired of reading Python documentation and thought that it was a good time to get my hands dirty in the code. After a while I had a simple sudoku solver. Nothing outstanding, just an interesting project to learn new programming language. Quite soon I realised that I need unit tests not only to protect functionality, but also to explore some neat language features. Covering code with test is simple and python has a good explanation in official documentation, but at some point I thought about code coverage, and that’s where I had some problems. Below I’ll provide short description of what was done to make it work as intended.

  • I’m using for code coverage, as it’s simple, well documented and popular. To install it use this command
python3 -m pip install coverage
  • Next make sure that your test code is executable as script. Complete documentation could be found here, but basically you just need to add these lines at the end of your test scipt
if __name__ == "__main__":
  • Now it’s time to execute test with code coverage. My project is named “likemammoth”. Include param specified for which files to collect coverage info. Note that I’m running coverage not by specifying test script, but rather module (you’ll also need file in each package in this case). This let’s me use in that is not visible easily, as is located in parent directory.
python3 -m coverage run --include=likemammoth/ -m likemammoth.test.test_puzzle

After this operation you should see how many tests passed and have .coverage file in your current directory

  • Next let’s generate readable report. The easiest what is to run
python3 -m coverage report

that will produce something like this

Name                    Stmts   Miss  Cover


likemammoth/     122     15    88%

Another option is to generate xml or html report.  In this case use

python3 -m coverage html

and if everything is good you’ll find “htmlcov” dir in your current working directory. Open index.html to see report.

  • Well actually that’s almost it. The last thing you’d like to do is to clean you space. Delete “htmlcov” manually and run
python3 -m coverage erase

to delete .coverage files.


That’s it for today. Not too much to gain, but hey, even tiny step forward is still good)

On my way to Python, or strayed developer story. Intro.

Please note that everything written below is just my personal observations, reasoning and conclusions. It may be useful to you, but do not consider it at as verified knowledge source, as information here may be incomplete or mistaken.

How did I come to this?

I’ve spent last 5 years working a java developer (trainee, junior, mid) and although I definitely didn’t reach any significant hights in my career I feel that I need something else to try. Java is great language. I really like a lot of language features and huge variety of applications for it, enormous amount of books/documentation/articles/frameworks, but I’m kinda tired of facing all the same tasks again and again. All of them usually boil down to gluing together frameworks and polishing rough solution with best practices until it shines.

That’s why I want a little bit more of “pure” programming. I want to be a software engineer, not just a java coder. I want to recall some fundamentals I’ve learned in the past and hopefully something new, to see other paradigms, approaches, workflows, pros and cons and so on. And one of the ways to “breath in” something new is to learn new programming language, and that’s what I’d like to do.

Why Python?

Well, frankly saying it was partially a blind choice. But only partially, as there were other reasons:

  1. It’s quite popular. Probably less than Java, but still it would be nice to have it in my resume.
  2. Comparing to Java it seemed not too different(like Lisp) and not too similar(like Scala), though providing something I wanted to try, like weak typing or using interpreted language.
  3. As far as I know Python shines in a little bit different tasks, like machine learning. Not like I’m ready to be an expert in this, but this sounds promising.


I’ve already wrote intro post for this blog, but this one seems to me very much like first one, except this one is less philosophical. I would say that it’s intro to technical branch, to understand myself a little bit better and figure out what I’m going to write here. My plan is to make a review of small (or not) parts of information I’ve learned. Hopefully it will let me understand this information better and deeper, will simplify process of recalling something I forgot, but I would be glad if it would help someone else.



I’m about to do my very first steps in blogging and I think that this post is the place for some kind of introduction, some explanations and little bit of my expectations. But let’s do this step-by-step

Who am I?

Let’s be honest, nobody cares. But if you do – there is a contact form and you can reach me via email.


For the last year or so I have a constant feeling that something is going wrong in my life. Well, maybe not exactly wrong, but definitely not the way I want it to be. I tried to change it a few times, and it did work, but for a short period of time, so I came up with an idea that I need something that will keep me moving forward all the time. Something that will motivate me to do that first little step that pushes on the road and cheers ups on the way. So I thought that blog is probably a good idea, because the necessity to write something leads to necessity to do something.


Have no idea what this will turn into. Probably I won’t even write my second post here, but speaking of now that’s what I’d like to achieve:

  • Self development is the main goal. I’ve named this blog “The Review Time” with an intention to review what I’ve done recently. At the moment I’m going to write some technical stuff, but that’s not a rule. We’ll see what this blog will turn into.
  • Practice my English. I have a grave doubt that anyone will read this someday, but again, if you do and you’re a native speaker (or at least fluent speaker) you probably have noticed a bunch of mistakes above. Don’t hesitate to write comments and let me know of my mistakes.
  • Very-very little chance, but maybe I’ll find nice people here. I don’t really expect this to happen, but life is unpredictable, so who knows)
  • Understand myself a little bit better.

Sort of conclusion

Well, it was much harder to write these few lines above than I expected. Challenging? Maybe. I’ll consider it as that little kick that pushed me on the new road and I’ll see where does it lead.