From 80d4ee7e11d97ccced4c9976854c0eb1a1d827d2 Mon Sep 17 00:00:00 2001 From: mrKazzila Date: Thu, 21 Sep 2023 15:47:44 +0300 Subject: [PATCH] test: add fixture for finder mock --- examples/miniapps/movie-lister/movies/tests.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/miniapps/movie-lister/movies/tests.py b/examples/miniapps/movie-lister/movies/tests.py index 1b29d824..1a133a5f 100644 --- a/examples/miniapps/movie-lister/movies/tests.py +++ b/examples/miniapps/movie-lister/movies/tests.py @@ -26,13 +26,18 @@ def container(): return container -def test_movies_directed_by(container): +@pytest.fixture +def finder_mock(container): finder_mock = mock.Mock() finder_mock.find_all.return_value = [ container.movie("The 33", 2015, "Patricia Riggen"), container.movie("The Jungle Book", 2016, "Jon Favreau"), ] + return finder_mock + + +def test_movies_directed_by(container, finder_mock): with container.finder.override(finder_mock): lister = container.lister() movies = lister.movies_directed_by("Jon Favreau") @@ -41,13 +46,7 @@ def test_movies_directed_by(container): assert movies[0].title == "The Jungle Book" -def test_movies_released_in(container): - finder_mock = mock.Mock() - finder_mock.find_all.return_value = [ - container.movie("The 33", 2015, "Patricia Riggen"), - container.movie("The Jungle Book", 2016, "Jon Favreau"), - ] - +def test_movies_released_in(container, finder_mock): with container.finder.override(finder_mock): lister = container.lister() movies = lister.movies_released_in(2015)