Skip to content

Karantan's blog

  • Home
  • Contact
  • About me

Tag: Unit testing

Jayden StewardSeptember 9, 2016

How to mock ‘open’ built-in function

Here is a code snippet on how to test open built-in function: Code to test: def my_function(self, id: int) -> None: file_path = ‘path/to/files/{}.txt’.format(id) with open(file_path, ‘w’) as f: f.write(‘< My data…

Continue reading
Jayden StewardSeptember 5, 2016September 5, 2016

How to mock __import__ built-in function

So lets say we need to write unit test for piece of code that uses  __import__  built-in function: def task_we_want_to_test(task_name: str, task_class: str, env: dict) -> Task: module = __import__(…

Continue reading
Jayden StewardApril 12, 2016April 15, 2016

More Python mocking: dictionary

In previous post we look at how basic mocking works and some examples. Today we will see how you can mock dict : post = { “name”: “test”, “content”: “tist”, }…

Continue reading
Jayden StewardJanuary 30, 2016January 30, 2016

Unit testing in Python with mock

Before we start writing tests let’s make sure that we understand why do we want to write unit tests and the concept of unit testing. Here are a few reasons (from my…

Continue reading


Archives

Tag Cloud

AI conda Git Go Lessons learned logs Magento Mock Mongodb nix nixops nixos PostgreSQL Python Python3 Rsync systemd tmux Unit testing
Proudly powered by WordPress | Theme: Gently by MusterThemes.