Switching to pytest
Switch to pytest
MODIFY
.travis.yml
.travis.yml
language: python
sudo: false
python:
- - pypy
- 2.6
- 2.7
- 3.4
@@ -10,6 +9,6 @@ python:
- pypy
- pypy3
install:
- - pip install flake8 check-manifest
+ - pip install pytest flake8 check-manifest
script:
- ./run-tests.sh

MODIFY
conda.recipe/meta.yaml
conda.recipe/meta.yaml
@@ -18,7 +18,7 @@ requirements:
test:
requires:
- - nose
+ - pytest
- flake8
about:

MODIFY
run-tests.sh
run-tests.sh
#!/bin/bash
-# Run tests suite, you can specify which nose to run by setting environment
-# variable `nose` (running without will use `nosetests`).
-# nose=nosetests-3.2 ./run-tests.sh
+# Run tests suite
# Exit on error
set -e
-echo "[$(date +%Y%m%dT%H%M%S)] ${USER}@$(hostname) :: $(python --version)"
+echo "[$(date +%Y%m%dT%H%M%S)] ${USER}@$(hostname) :: $(2>&1 python --version)"
echo
find . -name '*.pyc' -exec rm {} \;
@@ -19,7 +17,4 @@ fi
check-manifest --ignore 'fastavro/_*.c'
-nose=${nose-nosetests}
-echo "nose is $nose"
-
-$nose -vd $@ tests
+PYTHONPATH=${PWD} python -m pytest -v $@ tests

MODIFY
setup.py
setup.py
@@ -102,5 +102,5 @@ setup(
extras_require={
'snappy': ['python-snappy'],
},
- tests_require=['nose', 'flake8', 'check-manifest'],
+ tests_require=['pytest', 'flake8', 'check-manifest'],
)

MODIFY
tests/test_fastavro.py
tests/test_fastavro.py
import fastavro
-
from fastavro.six import MemoryIO
+
+import pytest
+
from os.path import join, abspath, dirname, basename
from glob import iglob
-from nose import SkipTest
-from nose.tools import raises
data_dir = join(abspath(dirname(__file__)), 'avro-files')
@@ -35,7 +35,15 @@ class NoSeekMemoryIO(object):
raise AssertionError("fastavro reader should not depend on seek")
-def check(filename):
+def _test_files():
+ for filename in iglob(join(data_dir, '*.avro')):
+ if (not has_snappy) and ('snappy' in filename):
+ continue
+ yield filename
+
+
+@pytest.mark.parametrize('filename', _test_files())
+def test_file(filename):
with open(filename, 'rb') as fo:
reader = fastavro.reader(fo)
assert hasattr(reader, 'schema'), 'no schema on file'
@@ -68,15 +76,8 @@ def check(filename):
assert new_records == records
-def test_fastavro():
- for filename in iglob(join(data_dir, '*.avro')):
- if (not has_snappy) and ('snappy' in filename):
- continue
- yield check, filename
-
-
-@raises(ValueError)
def test_not_avro():
+ with pytest.raises(ValueError):
with open(__file__, 'rb') as fo:
fastavro.reader(fo)
@@ -206,9 +207,9 @@ def test_compose_schemas():
assert 'Child' in fastavro._reader.READERS
-@raises(fastavro.schema.UnknownType)
def test_missing_schema():
schema_path = join(data_dir, 'ParentMissingChild.avsc')
+ with pytest.raises(fastavro.schema.UnknownType):
fastavro.schema.load_schema(schema_path)
@@ -594,7 +595,6 @@ def test_schema_migration_reader_union():
assert new_records == records
-@raises(fastavro._reader.SchemaResolutionError)
def test_schema_migration_union_failure():
schema = {
"type": "record",
@@ -618,10 +618,10 @@ def test_schema_migration_union_failure():
new_file.seek(0)
new_reader = fastavro.reader(new_file, new_schema)
+ with pytest.raises(fastavro._reader.SchemaResolutionError):
list(new_reader)
-@raises(fastavro._reader.SchemaResolutionError)
def test_schema_migration_array_failure():
schema = {
"type": "record",
@@ -650,10 +650,11 @@ def test_schema_migration_array_failure():
fastavro.writer(new_file, schema, records)
new_file.seek(0)
new_reader = fastavro.reader(new_file, new_schema)
+
+ with pytest.raises(fastavro._reader.SchemaResolutionError):
list(new_reader)
-@raises(fastavro._reader.SchemaResolutionError)
def test_schema_migration_maps_failure():
schema = {
"type": "record",
@@ -682,10 +683,10 @@ def test_schema_migration_maps_failure():
fastavro.writer(new_file, schema, records)
new_file.seek(0)
new_reader = fastavro.reader(new_file, new_schema)
+ with pytest.raises(fastavro._reader.SchemaResolutionError):
list(new_reader)
-@raises(fastavro._reader.SchemaResolutionError)
def test_schema_migration_enum_failure():
schema = {
"type": "enum",
@@ -704,10 +705,10 @@ def test_schema_migration_enum_failure():
fastavro.writer(new_file, schema, records)
new_file.seek(0)
new_reader = fastavro.reader(new_file, new_schema)
+ with pytest.raises(fastavro._reader.SchemaResolutionError):
list(new_reader)
-@raises(fastavro._reader.SchemaResolutionError)
def test_schema_migration_schema_mismatch():
schema = {
"type": "record",
@@ -728,10 +729,10 @@ def test_schema_migration_schema_mismatch():
fastavro.writer(new_file, schema, records)
new_file.seek(0)
new_reader = fastavro.reader(new_file, new_schema)
+ with pytest.raises(fastavro._reader.SchemaResolutionError):
list(new_reader)
-@raises(EOFError)
def test_empty():
io = MemoryIO()
schema = {
@@ -741,10 +742,10 @@ def test_empty():
{'type': 'boolean', 'name': 'a'}
],
}
+ with pytest.raises(EOFError):
fastavro.load(io, schema)
-@raises(ValueError)
def test_no_default():
io = MemoryIO()
schema = {
@@ -754,11 +755,13 @@ def test_no_default():
{'type': 'boolean', 'name': 'a'}
],
}
+ with pytest.raises(ValueError):
fastavro.writer(io, schema, [{}])
+@pytest.mark.skip(reason='FIXME: Add tests for write validator argument')
def test_validator():
- raise SkipTest('FIXME: Add tests for write validator argument')
+ pass
def test_is_avro_str():

MODIFY
tests/test_logical_types.py
tests/test_logical_types.py
-import datetime
+import fastavro
+
+import pytest
+
from decimal import Decimal
from io import BytesIO
-
-from nose.tools import raises
from uuid import uuid4
-import fastavro
+import datetime
+
schema = {
"fields": [
@@ -152,7 +154,7 @@ def test_leftmost():
assert (Decimal("-2.80") == data2)
-@raises(AssertionError)
def test_scale():
data1 = Decimal("123.456678") # does not fit scale
+ with pytest.raises(AssertionError):
serialize(schema_top, data1)

MODIFY
tests/test_schema_evolution.py
tests/test_schema_evolution.py
-import fastavro
-from io import BytesIO
-
from fastavro import writer as fastavro_writer
from fastavro.reader import SchemaResolutionError
-from nose.tools import raises
+import fastavro
+
+import pytest
+
+from io import BytesIO
schema_dict_a = {
"namespace": "example.avro2",
@@ -64,7 +65,7 @@ def test_evolution_add_field_with_default():
assert record_b.get("b") is None
-@raises(SchemaResolutionError)
def test_evolution_add_field_without_default():
+ with pytest.raises(SchemaResolutionError):
record_bytes_a = avro_to_bytes_with_schema(schema_dict_a, record_a)
bytes_with_schema_to_avro(schema_dict_a_c, record_bytes_a)

MODIFY
tests/test_types.py
tests/test_types.py
+import fastavro
+
+import pytest
+
from io import BytesIO
import sys
-import fastavro
-
-from nose import SkipTest
-from nose.tools import raises
schema = {
"fields": [
@@ -48,7 +48,6 @@ def test_types_match():
serialize(schema, *records)
-@raises(TypeError, ValueError)
def test_string_in_int_raises():
records = [{
'str_null': 'str',
@@ -57,10 +56,10 @@ def test_string_in_int_raises():
'integ': 21,
}]
+ with pytest.raises((TypeError, ValueError)):
serialize(schema, *records)
-@raises(TypeError, ValueError)
def test_string_in_int_null_raises():
records = [{
'str_null': 'str',
@@ -68,10 +67,10 @@ def test_string_in_int_null_raises():
'integ_null': 11,
'integ': 'str',
}]
+ with pytest.raises((TypeError, ValueError)):
serialize(schema, *records)
-@raises(TypeError, ValueError)
def test_int_in_string_null_raises():
records = [{
'str_null': 11,
@@ -79,14 +78,15 @@ def test_int_in_string_null_raises():
'integ_null': 21,
'integ': 21,
}]
+ with pytest.raises((TypeError, ValueError)):
serialize(schema, *records)
if sys.version_info[:2] == (3, 4):
+ @pytest.mark.skip(reason='FIXME: this fails on 3.4')
def test_int_in_string_raises():
- raise SkipTest('FIXME: this fails on 3.4')
+ pass
else:
- @raises(TypeError, ValueError, AttributeError)
def test_int_in_string_raises():
records = [{
'str_null': 'str',
@@ -95,4 +95,5 @@ else:
'integ': 21,
}]
+ with pytest.raises((TypeError, ValueError, AttributeError)):
serialize(schema, *records)

MODIFY
tox.ini
tox.ini
@@ -3,7 +3,7 @@ envlist = py26,py27,py34,py35,pypy,pypy3,packaging
[testenv]
deps =
- nose
+ pytest
flake8
commands = ./run-tests.sh

Switching to pytest (#95)

Switch to pytest