Skip to main content
The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. View results.

All Questions

Filter by
Sorted by
Tagged with
8 votes
2 answers
7k views

Mocking pathlib.Path I/O methods in a maintainable way which tests functionality not implementation

I have a function that constructs a path based on a function of inputs and creates the parent directory. When writing a unit test for this function, I want to mock the I/O part of the function, ...
gerrit's user avatar
  • 905
4 votes
2 answers
4k views

Fake utcnow for the pytest

I want to create a pytest with a fake utcnow, but also I need to preserve the functionality of all other datetime methods. ...
user avatar
3 votes
1 answer
1k views

Python unittest.mock.patch.object context manager

I want to test my core of handler, so I wrote this: ...
Denny's user avatar
  • 141
3 votes
1 answer
2k views

Using mocking to test that a Django view renders as expected

I have a Django view that ends with this... return render(request, 'define/see_all.html', context) I have mocked the render function and ...
Joff's user avatar
  • 263
6 votes
1 answer
3k views

Testing file IO errors in python

Below is a simple class with two methods: the first calls open() to read in a file. The second calls the first method and does error handling. There is also a ...
SJC's user avatar
  • 231
3 votes
2 answers
1k views

Unit Testing of parser method using pytest

This is my first time using pytest. All feedback for this test case is much appreciated. ...
fr00z1's user avatar
  • 534
7 votes
1 answer
351 views

Monkeypatching __builtin__ in tests for mocking

I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API requests. I want to test ...
Eddie Antonio Santos's user avatar