Make assertions before the "act" step #12572
-
|
Hi, I want to test a function that takes to 2 input videos. Those videos must be similar : same width, height and fps properties. I wrote an assertion function that makes those checks. Is it wrong to make those assertions before the act step ? If this is wrong, what is the right way to proceed ? def assert_similar_videos(video_path_1, video_path_2):
# Get video properties ...
assert width1 == width2 and height1 == height2
assert fps1 == fps2
def test_video_treatment():
# Test the input videos
assert_similar_videos(video_1, video_2)
# Do the treatment
video_treatment(video_1, video_2, parameters, output_video)
# Test the output video
assert output_video.exists()
assert_similar_videos(video_1, output_video)Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
I think that's perfectly fine! I sometimes explicitly mark those as You could also possibly do this in a fixture, as in: @pytest.fixture
def treatment_videos():
# get video1 and video2 from somewhere
assert_similar_videos(video_1, video_2)
return video_1, video_2
def test_video_treatment(treatment_videos):
video1, video2 = treatment_videos
...which would then result in the test being marked as |
Beta Was this translation helpful? Give feedback.
-
|
I am cleaning an existing code and the arguments are not exactly the same but I understand that I would be better to write the check as a fixture. |
Beta Was this translation helpful? Give feedback.
I think that's perfectly fine! I sometimes explicitly mark those as
# sanity checkso it's clearer that this is something that should never fail, and is just to ensure the test itself is actually working properly.You could also possibly do this in a fixture, as in:
which would then result in the test being marked as
E(error) instead ofF(failed) if that fails.