DEV Community

Phan Hieu Nguyen
Phan Hieu Nguyen

Posted on

Testing for Python, Github Action

Summary

I went to a lot of trouble to make it work this time.
Repo link
CI Action

Features

I added a test file and so far coverage is 50%. I added projects CI Action, it isn't perfect as I wanted but it works fine for now.

Challenges

Firstly, this is the time I can see the value of refactor. Because if I don't refactor my code, I cannot do any unit test on it. After some refactors, I started to write some test.
The real struggle I have at this point is importing other modules. It seems like impossible to use relative path when importing. I spent a lot of time looking for a simple solutions. There aren't any simple, always a long explanation that really doesn't at all. So I can only see one way, is to reorganize all files structure of my projects.
After moving everything, my tests started to work as it should be easy to be. An interesting thing I found out when writing test is I discovered a new thing to fake http response. I always have to test with real API or at least real back-end in the past. Now I know there are built in library for that.
Github action for build and test CI is simple enough. I used the default build and test for Python from Github. There is only a few things add and it work fine.
Writing test for other project is not a difficult task, especially the test coverage is low. But writing test in general will take a lot of time, because we need more tests for a function than coding for that function itself. So anyways, I worked on a C# project (not Python - surprise!!). The test was there, and the owner filed an issue that the test was not working properly like it suppose to be. After a few minute, I fixed it because his code was easy enough to understand. I didn't get any problem out of it.
So in the end, I kind of enjoy C# and very disappoint at Python because of relative path for now.

Top comments (0)