All Questions
Tagged with python unit-testing
67 questions
5
votes
5
answers
505
views
How to test for performance regression?
I am working on a refactor on a certain package (I can give details if asked). The package involves a clever lazy evaluation of a sort of nested sequence of arithmetic operations. If the numerical ...
2
votes
2
answers
532
views
Best practices for unit testing when breaking down functions into smaller ones
Say we have a function of the form
def func(num: int) -> int:
num = num + 1
num = 2 * num
num = num**3
return num
and let us act like each line is a long computation so that we ...
0
votes
2
answers
425
views
What is a good unit testing strategy against a chain of public method calls?
say I have this code which is a chain of public methods, public_c calls public_b calls public_a
def public_a(...):
...
def public_b(...):
...
public_a(...)
def public_c(...):
...
...
-1
votes
1
answer
172
views
Efficient way to write test cases depending on a Micro service
I'm very new to microservice architecture. In the Monolithic app structure, it was pretty straightforward to write test cases since everything was in one app. I have a situation where I manage a ...
-1
votes
1
answer
128
views
Software development in Python: unittests and assertions
I recently finished developing a piece of software in python where learning models and data processing procedures are contained within different class objects that succeed to each others (modules). As ...
2
votes
2
answers
343
views
What is a good way to call a unit-tested function provided by a library/package?
Consider the function foo provided by package X in Python. I want to test the different functionalities of X.foo, and then use X.foo in my code. To make sure that I am using X.foo as it was tested, I ...
0
votes
1
answer
242
views
How to properly isolate tests for dataframes with grouping?
I have the following problem:
I would like to test complex business logic for each test case completely separately, i.e. all tests should run in parallel. I don't want the test for customer #43 to ...
14
votes
3
answers
3k
views
Should I choose repeated code in unit test or test logic? Can I avoid both?
When writing unit tests, I feel that there is a trade-off between code repetition and test logic.
Example of my current (likely flawed) approach:
To test this function (overly simple function for ...
-1
votes
1
answer
572
views
How to write tests for a class that talks to a server without revealing connection implementation
I'm writing a class that acts as the interface to a server. The interface exposes a way to send messages to the server and pass messages back to the client through a callback. Implementations should ...
2
votes
3
answers
1k
views
Still don't understand when to mock and when not to
I've been trying to understand when to mock and when not to mock, however I'm not able to come up with a consistent guideline and I'm hoping to get some input on the subject. Let's look at the ...
0
votes
1
answer
1k
views
How to test a function with several conditional nested side effects
In Python, consider a function like the following:
def main(*args):
value1 = pure_function1(*args)
if condition(value1):
value = side_effect1(value1)
if value:
...
1
vote
3
answers
1k
views
Should I unit test functions internally used by API I expose?
I'm writing a CRUD app in Python that exposes web API. At first I wrote functions for communicating with DB and wrote tests for these functions.
def crud():
# do something with db
def test_crud():
...
2
votes
1
answer
2k
views
Should I check floating point values in a unit test?
We have unit tests that are running some underlying model. We provide it with some test input, and receive some outputs + floating point scores. What's a good practice from a unit-testing standpoint? ...
1
vote
1
answer
501
views
Python Unit Tests Mocking Imports - Removing Dependencies for CI/CD
I have a project written in python that I would like to create unit tests on.
This project has a dependency on a database project which is a sort of abstraction layer to data connections.
The issue ...
1
vote
1
answer
393
views
How to write tests in TDD for downloading and unpacking a file?
So I want to write this function that downloads a file and unpacks it in python using TDD.
The function will look like this approximately
import urllib.request
import tarfile
def download_and_unpack(...