Skip to content

Commit

Permalink
Remove pytest deprecated method (#19)
Browse files Browse the repository at this point in the history
- Replace all `def setup(self)` by `def setup_method(self, method)`
- Replace all `def teardown(self)` by `def teardown_method(self, method)`
  • Loading branch information
jowilf authored Nov 28, 2022
1 parent 079d162 commit bdb9ba1
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 deletions.
Empty file modified scripts/coverage.sh
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions tests/test_content_type_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __repr__(self):


class TestContentTypeValidator:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("content-type-validator"))
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_content_type_validator(
session.refresh(attachment)
assert attachment.content.file is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_image_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __repr__(self):


class TestImageField:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-image-field"))
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_create_image(self, fake_valid_image, fake_valid_image_content) -> None:
assert book.cover["width"] is not None
assert book.cover["height"] is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_image_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __repr__(self):


class TestImageValidator:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-image-validator"))
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_valid_image(self, fake_valid_image) -> None:
).scalar_one()
assert book.cover.file is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class TestMetadata:
def setup(self) -> None:
def setup_method(self, method) -> None:
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-metadata"))

Expand Down Expand Up @@ -44,5 +44,5 @@ def test_no_metadata(self):
assert stored_file.content_type == "application/octet-stream"
StorageManager.delete_file("test/test_metadata.txt")

def teardown(self):
def teardown_method(self, method):
StorageManager.get().delete()
4 changes: 2 additions & 2 deletions tests/test_multiple_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __repr__(self):


class TestMultipleField:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-multiple-field"))
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_delete_existing_multiple_content_rollback(self, fake_file) -> None:
for file_id in file_ids:
assert StorageManager.get().get_object(file_id) is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_multiple_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Attachment(Base):


class TestMultipleStorage:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("first", get_test_container("first"))
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_multiple_storage(self) -> None:
StorageManager.get("second").get_object(first_fileid)
session.rollback()

def teardown(self):
def teardown_method(self, method):
StorageManager.get("first").delete()
StorageManager.get("second").delete()
Base.metadata.drop_all(engine)
4 changes: 2 additions & 2 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __repr__(self):


class TestThumbnailGenerator:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-processor"))
Expand All @@ -70,7 +70,7 @@ def test_create_image_with_thumbnail(self, fake_image) -> None:
assert book.cover["thumbnail"]["width"] == thumbnail.width
assert book.cover["thumbnail"]["height"] == thumbnail.height

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_result_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __repr__(self):


class TestResultValue:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_dummy_container("test-result-value"))
Expand Down Expand Up @@ -147,5 +147,5 @@ def test_multiple_column_cannot_edit_after_save(self) -> None:
with pytest.raises(TypeError):
delattr(content, "dummy_attr")

def teardown(self):
def teardown_method(self, method):
Base.metadata.drop_all(engine)
4 changes: 2 additions & 2 deletions tests/test_single_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __repr__(self):


class TestSingleField:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-simple-field"))
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_relationship_cascade_delete_rollback(
session.rollback()
assert StorageManager.get_file(file_path) is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_size_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __repr__(self):


class TestSizeValidator:
def setup(self) -> None:
def setup_method(self, method) -> None:
Base.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-size-validator"))
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_size_validator_valid_size(self, fake_valid_file) -> None:
print(attachment.content.file)
assert attachment.content.file is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sqlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Attachment(SQLModel, table=True):


class TestSQLModel:
def setup(self) -> None:
def setup_method(self, method) -> None:
SQLModel.metadata.create_all(engine)
StorageManager._clear()
StorageManager.add_storage("test", get_test_container("test-sqlmodel"))
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_delete_existing_rollback(self, fake_file) -> None:
session.rollback()
assert StorageManager.get().get_object(file_id) is not None

def teardown(self):
def teardown_method(self, method):
for obj in StorageManager.get().list_objects():
obj.delete()
StorageManager.get().delete()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_storage_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestStorageManager:
def setup(self) -> None:
def setup_method(self, method) -> None:
StorageManager._clear()

def test_first_configured_is_default(self) -> None:
Expand Down

0 comments on commit bdb9ba1

Please sign in to comment.