fix tests for new version of pytest
MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
@@ -728,11 +728,11 @@ def test_schema_migration_schema_mismatch():
def test_empty():
io = MemoryIO()
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(
+ ValueError, match="cannot read header - is it an avro file?"
+ ):
fastavro.reader(io)
- assert 'cannot read header - is it an avro file?' in str(exc)
-
def test_no_default():
io = MemoryIO()
@@ -743,11 +743,9 @@ def test_no_default():
{'type': 'boolean', 'name': 'a'}
],
}
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(ValueError, match="no value and no default"):
fastavro.writer(io, schema, [{}])
- assert 'no value and no default' in str(exc)
-
def test_is_avro_str():
for path in iglob('%s/*.avro' % data_dir):
@@ -1495,11 +1493,11 @@ def test_helpful_error_when_a_single_record_is_passed_to_writer():
}
new_file = MemoryIO()
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(
+ ValueError, match="argument should be an iterable, not dict"
+ ):
fastavro.writer(new_file, schema, record)
- assert "argument should be an iterable, not dict" in str(exc)
-
def test_embedded_records_get_namespaced_correctly():
schema = {
@@ -1665,11 +1663,11 @@ def test_appending_records_wrong_mode_fails(tmpdir):
fastavro.writer(new_file, schema, [{"field": "foo"}])
with open(test_file, "ab") as new_file:
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(
+ ValueError, match=r"you must use the 'a\+' mode, not just 'a'"
+ ):
fastavro.writer(new_file, schema, [{"field": "bar"}])
- assert "you must use the 'a+' mode, not just 'a'" in str(exc)
-
def test_appending_records_different_schema_fails(tmpdir):
"""https://github.com/fastavro/fastavro/issues/276"""
@@ -1697,11 +1695,11 @@ def test_appending_records_different_schema_fails(tmpdir):
}
with open(test_file, "a+b") as new_file:
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(
+ ValueError, match="does not match file writer_schema"
+ ):
fastavro.writer(new_file, different_schema, [{"field": 1}])
- assert "does not match file writer_schema" in str(exc)
-
def test_user_specified_sync():
"""https://github.com/fastavro/fastavro/issues/300"""

MODIFY
tests/test_schema.py
tests/test_schema.py
@@ -123,11 +123,11 @@ def test_scale_is_an_int():
}],
}
- with pytest.raises(SchemaParseException) as exc:
+ with pytest.raises(
+ SchemaParseException, match="decimal scale must be a postive integer"
+ ):
parse_schema(schema)
- assert "decimal scale must be a postive integer" in str(exc)
-
def test_precision_is_an_int():
"""https://github.com/fastavro/fastavro/issues/262"""
@@ -145,11 +145,12 @@ def test_precision_is_an_int():
}],
}
- with pytest.raises(SchemaParseException) as exc:
+ with pytest.raises(
+ SchemaParseException,
+ match="decimal precision must be a postive integer",
+ ):
parse_schema(schema)
- assert "decimal precision must be a postive integer" in str(exc)
-
def test_named_type_cannot_be_redefined():
schema = {
@@ -178,11 +179,12 @@ def test_named_type_cannot_be_redefined():
}],
}
- with pytest.raises(SchemaParseException) as exc:
+ with pytest.raises(
+ SchemaParseException,
+ match="redefined named type: test.avro.training.SomeMessage",
+ ):
parse_schema(schema)
- assert "redefined named type: test.avro.training.SomeMessage" in str(exc)
-
schema = {
"type": "record",
"name": "SomeMessage",
@@ -203,11 +205,11 @@ def test_named_type_cannot_be_redefined():
}],
}
- with pytest.raises(SchemaParseException) as exc:
+ with pytest.raises(
+ SchemaParseException, match="redefined named type: ThisName"
+ ):
parse_schema(schema)
- assert "redefined named type: ThisName" in str(exc)
-
schema = {
"type": "record",
"name": "SomeMessage",
@@ -228,7 +230,7 @@ def test_named_type_cannot_be_redefined():
}],
}
- with pytest.raises(SchemaParseException) as exc:
+ with pytest.raises(
+ SchemaParseException, match="redefined named type: ThatName"
+ ):
parse_schema(schema)
-
- assert "redefined named type: ThatName" in str(exc)

MODIFY
tests/test_six.py
tests/test_six.py
@@ -9,9 +9,8 @@ def test_appendable_raises_valuerror(tmpdir):
with open(test_file, "a") as new_file:
new_file.write('this phrase forwards cursor position beyond zero')
- with pytest.raises(ValueError) as exc:
+ with pytest.raises(ValueError, match=r"you must use the 'a\+' mode"):
appendable(new_file)
- assert "you must use the 'a+' mode" in str(exc)
def test_appendable_true_nonzero(tmpdir):

fix tests for new version of pytest