Fix Pytest's deprecation warnings about nose usage (#8758)

Pytest 7.2.0 deprecated plain `setup` and `teardown` functions and
methods as nose idioms:
https://docs.pytest.org/en/latest/changelog.html#pytest-7-2-0-2022-10-23

`setup` can be safely replaced with `setup_method`:
https://docs.pytest.org/en/stable/deprecations.html#setup-teardown

Fixes: https://github.com/encode/django-rest-framework/issues/8757
Signed-off-by: Stanislav Levin <slev@altlinux.org>

Signed-off-by: Stanislav Levin <slev@altlinux.org>
This commit is contained in:
Stanislav Levin 2022-11-15 15:29:15 +03:00 committed by GitHub
parent ae7a2b0dfa
commit 78cdae6999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 32 deletions

View File

@ -239,7 +239,7 @@ class TestSource:
class TestReadOnly: class TestReadOnly:
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
read_only = serializers.ReadOnlyField(default="789") read_only = serializers.ReadOnlyField(default="789")
writable = serializers.IntegerField() writable = serializers.IntegerField()
@ -271,7 +271,7 @@ class TestReadOnly:
class TestWriteOnly: class TestWriteOnly:
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
write_only = serializers.IntegerField(write_only=True) write_only = serializers.IntegerField(write_only=True)
readable = serializers.IntegerField() readable = serializers.IntegerField()
@ -296,7 +296,7 @@ class TestWriteOnly:
class TestInitial: class TestInitial:
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
initial_field = serializers.IntegerField(initial=123) initial_field = serializers.IntegerField(initial=123)
blank_field = serializers.IntegerField() blank_field = serializers.IntegerField()
@ -313,7 +313,7 @@ class TestInitial:
class TestInitialWithCallable: class TestInitialWithCallable:
def setup(self): def setup_method(self):
def initial_value(): def initial_value():
return 123 return 123
@ -331,7 +331,7 @@ class TestInitialWithCallable:
class TestLabel: class TestLabel:
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
labeled = serializers.IntegerField(label='My label') labeled = serializers.IntegerField(label='My label')
self.serializer = TestSerializer() self.serializer = TestSerializer()
@ -345,7 +345,7 @@ class TestLabel:
class TestInvalidErrorKey: class TestInvalidErrorKey:
def setup(self): def setup_method(self):
class ExampleField(serializers.Field): class ExampleField(serializers.Field):
def to_native(self, data): def to_native(self, data):
self.fail('incorrect') self.fail('incorrect')
@ -539,7 +539,7 @@ class TestHTMLInput:
class TestCreateOnlyDefault: class TestCreateOnlyDefault:
def setup(self): def setup_method(self):
default = serializers.CreateOnlyDefault('2001-01-01') default = serializers.CreateOnlyDefault('2001-01-01')
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):

View File

@ -18,7 +18,7 @@ class TestPaginationIntegration:
Integration tests. Integration tests.
""" """
def setup(self): def setup_method(self):
class PassThroughSerializer(serializers.BaseSerializer): class PassThroughSerializer(serializers.BaseSerializer):
def to_representation(self, item): def to_representation(self, item):
return item return item
@ -140,7 +140,7 @@ class TestPaginationDisabledIntegration:
Integration tests for disabled pagination. Integration tests for disabled pagination.
""" """
def setup(self): def setup_method(self):
class PassThroughSerializer(serializers.BaseSerializer): class PassThroughSerializer(serializers.BaseSerializer):
def to_representation(self, item): def to_representation(self, item):
return item return item
@ -163,7 +163,7 @@ class TestPageNumberPagination:
Unit tests for `pagination.PageNumberPagination`. Unit tests for `pagination.PageNumberPagination`.
""" """
def setup(self): def setup_method(self):
class ExamplePagination(pagination.PageNumberPagination): class ExamplePagination(pagination.PageNumberPagination):
page_size = 5 page_size = 5
@ -302,7 +302,7 @@ class TestPageNumberPaginationOverride:
the Django Paginator Class is overridden. the Django Paginator Class is overridden.
""" """
def setup(self): def setup_method(self):
class OverriddenDjangoPaginator(DjangoPaginator): class OverriddenDjangoPaginator(DjangoPaginator):
# override the count in our overridden Django Paginator # override the count in our overridden Django Paginator
# we will only return one page, with one item # we will only return one page, with one item
@ -358,7 +358,7 @@ class TestLimitOffset:
Unit tests for `pagination.LimitOffsetPagination`. Unit tests for `pagination.LimitOffsetPagination`.
""" """
def setup(self): def setup_method(self):
class ExamplePagination(pagination.LimitOffsetPagination): class ExamplePagination(pagination.LimitOffsetPagination):
default_limit = 10 default_limit = 10
max_limit = 15 max_limit = 15
@ -941,7 +941,7 @@ class TestCursorPagination(CursorPaginationTestsMixin):
Unit tests for `pagination.CursorPagination`. Unit tests for `pagination.CursorPagination`.
""" """
def setup(self): def setup_method(self):
class MockObject: class MockObject:
def __init__(self, idx): def __init__(self, idx):
self.created = idx self.created = idx

View File

@ -374,7 +374,7 @@ class TestManyRelatedField(APISimpleTestCase):
class TestHyperlink: class TestHyperlink:
def setup(self): def setup_method(self):
self.default_hyperlink = serializers.Hyperlink('http://example.com', 'test') self.default_hyperlink = serializers.Hyperlink('http://example.com', 'test')
def test_can_be_pickled(self): def test_can_be_pickled(self):

View File

@ -61,7 +61,7 @@ class TestFieldImports:
# ----------------------------- # -----------------------------
class TestSerializer: class TestSerializer:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
char = serializers.CharField() char = serializers.CharField()
integer = serializers.IntegerField() integer = serializers.IntegerField()
@ -240,7 +240,7 @@ class TestValidateMethod:
class TestBaseSerializer: class TestBaseSerializer:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.BaseSerializer): class ExampleSerializer(serializers.BaseSerializer):
def to_representation(self, obj): def to_representation(self, obj):
return { return {
@ -337,7 +337,7 @@ class TestStarredSource:
'nested2': {'c': 3, 'd': 4} 'nested2': {'c': 3, 'd': 4}
} }
def setup(self): def setup_method(self):
class NestedSerializer1(serializers.Serializer): class NestedSerializer1(serializers.Serializer):
a = serializers.IntegerField() a = serializers.IntegerField()
b = serializers.IntegerField() b = serializers.IntegerField()
@ -463,7 +463,7 @@ class TestNotRequiredOutput:
class TestDefaultOutput: class TestDefaultOutput:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
has_default = serializers.CharField(default='x') has_default = serializers.CharField(default='x')
has_default_callable = serializers.CharField(default=lambda: 'y') has_default_callable = serializers.CharField(default=lambda: 'y')
@ -584,7 +584,7 @@ class TestCacheSerializerData:
class TestDefaultInclusions: class TestDefaultInclusions:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
char = serializers.CharField(default='abc') char = serializers.CharField(default='abc')
integer = serializers.IntegerField() integer = serializers.IntegerField()
@ -612,7 +612,7 @@ class TestDefaultInclusions:
class TestSerializerValidationWithCompiledRegexField: class TestSerializerValidationWithCompiledRegexField:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
name = serializers.RegexField(re.compile(r'\d'), required=True) name = serializers.RegexField(re.compile(r'\d'), required=True)
self.Serializer = ExampleSerializer self.Serializer = ExampleSerializer
@ -641,7 +641,7 @@ class Test2555Regression:
class Test4606Regression: class Test4606Regression:
def setup(self): def setup_method(self):
class ExampleSerializer(serializers.Serializer): class ExampleSerializer(serializers.Serializer):
name = serializers.CharField(required=True) name = serializers.CharField(required=True)
choices = serializers.CharField(required=True) choices = serializers.CharField(required=True)

View File

@ -32,7 +32,7 @@ class TestListSerializer:
Note that this is in contrast to using ListSerializer as a field. Note that this is in contrast to using ListSerializer as a field.
""" """
def setup(self): def setup_method(self):
class IntegerListSerializer(serializers.ListSerializer): class IntegerListSerializer(serializers.ListSerializer):
child = serializers.IntegerField() child = serializers.IntegerField()
self.Serializer = IntegerListSerializer self.Serializer = IntegerListSerializer
@ -70,7 +70,7 @@ class TestListSerializerContainingNestedSerializer:
Tests for using a ListSerializer containing another serializer. Tests for using a ListSerializer containing another serializer.
""" """
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
integer = serializers.IntegerField() integer = serializers.IntegerField()
boolean = serializers.BooleanField() boolean = serializers.BooleanField()
@ -156,7 +156,7 @@ class TestNestedListSerializer:
Tests for using a ListSerializer as a field. Tests for using a ListSerializer as a field.
""" """
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
integers = serializers.ListSerializer(child=serializers.IntegerField()) integers = serializers.ListSerializer(child=serializers.IntegerField())
booleans = serializers.ListSerializer(child=serializers.BooleanField()) booleans = serializers.ListSerializer(child=serializers.BooleanField())
@ -278,7 +278,7 @@ class TestNestedListSerializerAllowEmpty:
class TestNestedListOfListsSerializer: class TestNestedListOfListsSerializer:
def setup(self): def setup_method(self):
class TestSerializer(serializers.Serializer): class TestSerializer(serializers.Serializer):
integers = serializers.ListSerializer( integers = serializers.ListSerializer(
child=serializers.ListSerializer( child=serializers.ListSerializer(
@ -594,7 +594,7 @@ class TestEmptyListSerializer:
Tests the behaviour of ListSerializers when there is no data passed to it Tests the behaviour of ListSerializers when there is no data passed to it
""" """
def setup(self): def setup_method(self):
class ExampleListSerializer(serializers.ListSerializer): class ExampleListSerializer(serializers.ListSerializer):
child = serializers.IntegerField() child = serializers.IntegerField()
@ -623,7 +623,7 @@ class TestMaxMinLengthListSerializer:
Tests the behaviour of ListSerializers when max_length and min_length are used Tests the behaviour of ListSerializers when max_length and min_length are used
""" """
def setup(self): def setup_method(self):
class IntegerSerializer(serializers.Serializer): class IntegerSerializer(serializers.Serializer):
some_int = serializers.IntegerField() some_int = serializers.IntegerField()

View File

@ -9,7 +9,7 @@ from rest_framework.serializers import raise_errors_on_nested_writes
class TestNestedSerializer: class TestNestedSerializer:
def setup(self): def setup_method(self):
class NestedSerializer(serializers.Serializer): class NestedSerializer(serializers.Serializer):
one = serializers.IntegerField(max_value=10) one = serializers.IntegerField(max_value=10)
two = serializers.IntegerField(max_value=10) two = serializers.IntegerField(max_value=10)
@ -54,7 +54,7 @@ class TestNestedSerializer:
class TestNotRequiredNestedSerializer: class TestNotRequiredNestedSerializer:
def setup(self): def setup_method(self):
class NestedSerializer(serializers.Serializer): class NestedSerializer(serializers.Serializer):
one = serializers.IntegerField(max_value=10) one = serializers.IntegerField(max_value=10)
@ -83,7 +83,7 @@ class TestNotRequiredNestedSerializer:
class TestNestedSerializerWithMany: class TestNestedSerializerWithMany:
def setup(self): def setup_method(self):
class NestedSerializer(serializers.Serializer): class NestedSerializer(serializers.Serializer):
example = serializers.IntegerField(max_value=10) example = serializers.IntegerField(max_value=10)
@ -181,7 +181,7 @@ class TestNestedSerializerWithMany:
class TestNestedSerializerWithList: class TestNestedSerializerWithList:
def setup(self): def setup_method(self):
class NestedSerializer(serializers.Serializer): class NestedSerializer(serializers.Serializer):
example = serializers.MultipleChoiceField(choices=[1, 2, 3]) example = serializers.MultipleChoiceField(choices=[1, 2, 3])
@ -210,7 +210,7 @@ class TestNestedSerializerWithList:
class TestNotRequiredNestedSerializerWithMany: class TestNotRequiredNestedSerializerWithMany:
def setup(self): def setup_method(self):
class NestedSerializer(serializers.Serializer): class NestedSerializer(serializers.Serializer):
one = serializers.IntegerField(max_value=10) one = serializers.IntegerField(max_value=10)