Skip to content

Commit

Permalink
Replace custom test runner with pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilStenstrom committed Jul 12, 2024
1 parent acf06d8 commit a20476d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 147 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ include = ["conllu"]
[tool.setuptools.package-data]
"conllu" = ["py.typed"]

[tool.pytest.ini_options]
markers = [
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
]
[tool.flake8]
ignore = "E302, W503"
max-line-length = 119
Expand Down
101 changes: 0 additions & 101 deletions runtests.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
from io import StringIO


def testlabel(*labels):
"""
Usage::
@testlabel('quick')
class MyTest(unittest.TestCase):
def test_foo(self):
pass
"""
def inner(cls):
# append labels to class
cls._labels = set(labels) | getattr(cls, '_labels', set())

return cls

return inner

def capture_print(func, args=None):
f = StringIO()
with redirect_stdout(f):
Expand Down
12 changes: 7 additions & 5 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from io import StringIO
from textwrap import dedent

import pytest

from conllu import parse, parse_incr, parse_tree, parse_tree_incr
from conllu.models import Token, TokenList
from conllu.parser import parse_dict_value, parse_int_value
from tests.helpers import capture_print, testlabel
from tests.helpers import capture_print


@testlabel("integration")
@pytest.mark.integration
class TestParse(unittest.TestCase):
maxDiff = None

Expand Down Expand Up @@ -152,7 +154,7 @@ def test_parse_tree_incr(self):
self.assertEqual(parse_tree(self.data), list(parse_tree_incr(StringIO(self.data))))


@testlabel("integration")
@pytest.mark.integration
class TestTrickyCases(unittest.TestCase):
maxDiff = None

Expand All @@ -175,7 +177,7 @@ def test_parse_tree_and_serialize(self):
self.assertEqual(parse_tree(testcase)[0].serialize(), testcase_without_range_and_elided.serialize())


@testlabel("integration")
@pytest.mark.integration
class TestParseCoNLLUPlus(unittest.TestCase):
def test_parse_conllu_plus(self):
# Note: global.columns affects both sentences
Expand Down Expand Up @@ -241,7 +243,7 @@ def test_parse_conllu_plus(self):
})


@testlabel("integration")
@pytest.mark.integration
class TestParseCoNLL2009(unittest.TestCase):
def test_parse_CoNLL2009_1(self):
data = dedent("""\
Expand Down
39 changes: 14 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ envlist =
isort
mypy
requires =
virtualenv<=20.21.1
virtualenv<=20.21.1
isolated_build = True

[gh-actions]
Expand All @@ -29,51 +29,40 @@ python =
fail_on_no_env = True

[testenv]
allowlist_externals =
find
setenv =
PYTHONWARNINGS=once::DeprecationWarning
commands =
python runtests.py

[cleanup]
commands =
find {toxinidir}/conllu -type f -name "*.pyc" -delete
find {toxinidir}/conllu -type d -name "__pycache__" -delete
find {toxinidir} -type f -path "*.egg-info*" -delete
find {toxinidir} -type d -path "*.egg-info" -delete
package = wheel
wheel_build_env = .pkg
deps = pytest
commands = python -m pytest {posargs}

[testenv:flake8]
# Note: Settings for flake8 exists in the setup.cfg file
# Note: Settings for flake8 exists in the pyproject.toml file
changedir = {toxinidir}
deps =
flake8
flake8-pyproject
commands =
flake8 conllu tests
{[cleanup]commands}

[testenv:isort]
# Note: Settings for isort exists in the setup.cfg file
# Note: Settings for isort exists in the pyproject.toml file
changedir = {toxinidir}
deps = isort
commands =
isort --check-only --diff conllu tests
{[cleanup]commands}

[testenv:coverage]
# Note: Settings for coverage exists in the setup.cfg file
# Note: Settings for coverage exists in the pyproject.toml file
changedir = {toxinidir}
deps = coverage
deps = pytest-coverage
commands =
coverage run --branch runtests.py --blacklist integration
coverage run --branch -m pytest -m "not integration"
coverage report -m --fail-under=100
{[cleanup]commands}

[testenv:mypy]
# Note: Settings for coverage exists in the setup.cfg file
# Note: Settings for coverage exists in the pyproject.toml file
changedir = {toxinidir}
deps = mypy
deps =
mypy
pytest
commands =
mypy .
{[cleanup]commands}

0 comments on commit a20476d

Please sign in to comment.