Apply shared fixtures to whole test classes

This commit is contained in:
Alexander Hess 2026-11-28 03:52:11 +01:00
commit afe8b3ce90
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -198,6 +198,7 @@ class TestConstraints:
@pytest.mark.db @pytest.mark.db
@pytest.mark.usefixtures("_prepare_db")
class TestFromAddresses: class TestFromAddresses:
"""Test the alternative constructor `Path.from_addresses()`. """Test the alternative constructor `Path.from_addresses()`.
@ -214,7 +215,6 @@ class TestFromAddresses:
""" """
db_session.add(address) db_session.add(address)
@pytest.mark.usefixtures("_prepare_db")
def test_make_path_instance( def test_make_path_instance(
self, self,
db_session, db_session,
@ -228,7 +228,6 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1 assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures("_prepare_db")
def test_make_the_same_path_instance_twice( def test_make_the_same_path_instance_twice(
self, self,
db_session, db_session,
@ -246,14 +245,12 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1 assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures("_prepare_db")
def test_structure_of_return_value(self, address, another_address): def test_structure_of_return_value(self, address, another_address):
"""Test instantiation of a new `Path` instance.""" """Test instantiation of a new `Path` instance."""
results = db.Path.from_addresses(address, another_address) results = db.Path.from_addresses(address, another_address)
assert isinstance(results, list) assert isinstance(results, list)
@pytest.mark.usefixtures("_prepare_db")
def test_instances_must_have_air_distance( def test_instances_must_have_air_distance(
self, self,
address, address,
@ -266,7 +263,6 @@ class TestFromAddresses:
assert result.air_distance is not None assert result.air_distance is not None
@pytest.mark.usefixtures("_prepare_db")
def test_do_not_sync_instances_with_google_maps( def test_do_not_sync_instances_with_google_maps(
self, self,
address, address,
@ -280,7 +276,6 @@ class TestFromAddresses:
assert result.bicycle_distance is None assert result.bicycle_distance is None
assert result.bicycle_duration is None assert result.bicycle_duration is None
@pytest.mark.usefixtures("_prepare_db")
def test_sync_instances_with_google_maps( def test_sync_instances_with_google_maps(
self, self,
address, address,
@ -302,21 +297,18 @@ class TestFromAddresses:
assert result.bicycle_distance is not None assert result.bicycle_distance is not None
assert result.bicycle_duration is not None assert result.bicycle_duration is not None
@pytest.mark.usefixtures("_prepare_db")
def test_one_path_for_two_addresses(self, address, another_address): def test_one_path_for_two_addresses(self, address, another_address):
"""Test instantiation of a new `Path` instance.""" """Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(address, another_address)) result = len(db.Path.from_addresses(address, another_address))
assert result == 1 assert result == 1
@pytest.mark.usefixtures("_prepare_db")
def test_two_paths_for_three_addresses(self, make_address): def test_two_paths_for_three_addresses(self, make_address):
"""Test instantiation of a new `Path` instance.""" """Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(*[make_address() for _ in range(3)])) result = len(db.Path.from_addresses(*[make_address() for _ in range(3)]))
assert result == 3 assert result == 3
@pytest.mark.usefixtures("_prepare_db")
def test_six_paths_for_four_addresses(self, make_address): def test_six_paths_for_four_addresses(self, make_address):
"""Test instantiation of a new `Path` instance.""" """Test instantiation of a new `Path` instance."""
result = len(db.Path.from_addresses(*[make_address() for _ in range(4)])) result = len(db.Path.from_addresses(*[make_address() for _ in range(4)]))
@ -325,7 +317,6 @@ class TestFromAddresses:
# Tests for the `Path.from_order()` convenience method. # Tests for the `Path.from_order()` convenience method.
@pytest.mark.usefixtures("_prepare_db")
def test_make_path_instance_from_order( def test_make_path_instance_from_order(
self, self,
db_session, db_session,
@ -338,7 +329,6 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1 assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures("_prepare_db")
def test_make_the_same_path_instance_from_order_twice( def test_make_the_same_path_instance_from_order_twice(
self, self,
db_session, db_session,
@ -355,14 +345,12 @@ class TestFromAddresses:
assert db_session.query(db.Path).count() == 1 assert db_session.query(db.Path).count() == 1
@pytest.mark.usefixtures("_prepare_db")
def test_structure_of_return_value_from_order(self, order): def test_structure_of_return_value_from_order(self, order):
"""Test instantiation of a new `Path` instance.""" """Test instantiation of a new `Path` instance."""
result = db.Path.from_order(order) result = db.Path.from_order(order)
assert isinstance(result, db.Path) assert isinstance(result, db.Path)
@pytest.mark.usefixtures("_prepare_db")
def test_sync_instance_from_order_with_google_maps( def test_sync_instance_from_order_with_google_maps(
self, self,
order, order,
@ -383,6 +371,7 @@ class TestFromAddresses:
@pytest.mark.db @pytest.mark.db
@pytest.mark.usefixtures("_fake_google_api", "db_session")
class TestSyncWithGoogleMaps: class TestSyncWithGoogleMaps:
"""Test the `Path.sync_with_google_maps()` method.""" """Test the `Path.sync_with_google_maps()` method."""
@ -648,7 +637,6 @@ class TestSyncWithGoogleMaps:
monkeypatch.setattr(googlemaps.Client, "directions", directions) monkeypatch.setattr(googlemaps.Client, "directions", directions)
@pytest.mark.usefixtures("_fake_google_api", "db_session")
def test_sync_instances_with_google_maps(self, path): def test_sync_instances_with_google_maps(self, path):
"""Call the method for a `Path` object without Google data.""" """Call the method for a `Path` object without Google data."""
path.bicycle_distance = None path.bicycle_distance = None
@ -661,7 +649,6 @@ class TestSyncWithGoogleMaps:
assert path.bicycle_duration == 596 assert path.bicycle_duration == 596
assert path._directions is not None assert path._directions is not None
@pytest.mark.usefixtures("_fake_google_api", "db_session")
def test_repeated_sync_instances_with_google_maps(self, path): def test_repeated_sync_instances_with_google_maps(self, path):
"""Call the method for a `Path` object with Google data. """Call the method for a `Path` object with Google data.