-1

Let's say you have a function to retrieve data from the database. Since the data changes frequently and the output for function like "get the nearest log of the system log" will have different output each time you call it. How do you properly write a Unit Test for this function? Is there any python library, framework to help you do it?

Le D. Thang
  • 613
  • 1
  • 7
  • 11

1 Answers1

0

You generally want to mock out pieces of your software that your the object under test depends on. Python3 provides unittest.mock which has all sorts of helpers for mocking out dependencies. However sometimes the simplest solution is to just create your own mock that provides consistent data that you can test against.

rsiemens
  • 615
  • 6
  • 15