Lets say I generate some input numpy array data using a np.random.normal() in my test_func.py script that is using pytest.
Now I want to call the func.py function that I am testing. How am I able to get testable results? If I set a seed in the test_func.py script, it isn't going to correspond to the random data that gets generated in the func.py function, correct?
I want to be able to create some reference data in test_func.py and then test that the randomness generated in the func.py script is comparable to the reference data I created (hence, testing the randomness and functionality of the func.py function).
Thank you!
EDIT: Here is some sample code to describe my process:
# func.py
import numpy as np
# I send in a numpy array signal, generate noise, and append noise to signal
def generate_random_noise(signal):
noise = np.random.normal(0, 5, signal.shape)
signal_w_noise = signal + noise
return signal_w_noise
# test_func.py
import pytest
import numpy as np
import func
def test_generate_random_noise():
# create reference signal
# ...
np.random.seed(5)
reference_noise = np.random.normal(0, 5, ref_signal.shape)
ref_signal_w_noise = ref_signal + reference_noise
# assert manually created signal and noise and
assert all(np.array_equal(x, y) for x, y in zip(generate_random_noise(reference_signal), ref_signal_w_noise))