Skip to content

Commit

Permalink
[TEST] Move pytest config to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Aedial committed Apr 27, 2023
1 parent be02c90 commit 9b994a6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def test_api(session: nox.Session):
session.run("npm", "install", "fflate", external=True)

if session.posargs:
session.run("pytest", "--tb=short", *(f"tests/api/{e}" for e in session.posargs))
session.run("pytest", *(f"tests/api/{e}" for e in session.posargs))
else:
session.run("pytest", "--tb=short", "tests/api/")
session.run("pytest", "tests/api/")


@nox.session()
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ regex = "^2022.10.31"
sentencepiece = "^0.1.98"

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
pytest-asyncio = "^0.20.1"
pytest-randomly = "^3.12.0"
pylint = "^2.15.5"

[tool.flake8]
# TODO: add flake when supports come
# TODO: add flake when supports come (https://github.com/PyCQA/flake8/issues/234)

[tool.bandit]
exclude_dirs = ["tests/api/test_decrypt_encrypt_integrity_check.py"]
Expand Down Expand Up @@ -78,6 +79,12 @@ from pylint.config import find_default_config_files
path.extend(p.parent for p in find_default_config_files())
"""

[tool.pytest.ini_options]
xfail_strict = true
empty_parameter_set_mark = "fail_at_collect"
asyncio_mode = "auto"
addopts = "--tb=short"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
25 changes: 25 additions & 0 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import asyncio
from typing import List

import pytest


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_terminal_summary(terminalreporter):
yield

xfailed: List[pytest.TestReport] = terminalreporter.stats.get("xfailed", [])
if xfailed:
terminalreporter.write_sep("=", "XFAIL summary info", cyan=True, bold=True)

for rep in xfailed:
reason = getattr(rep, "wasxfail", "")
terminalreporter.write("XFAIL", yellow=True)
terminalreporter.write(f" {rep.nodeid} - {reason}\n")

rep.longrepr.toterminal(terminalreporter._tw)
terminalreporter.line("")


# cannot put in boilerplate because pytest is a mess
@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop()
yield loop

# clean any remaining task to avoid the warning about pending tasks
tasks = asyncio.Task.all_tasks(loop) if hasattr(asyncio.Task, "all_tasks") else asyncio.all_tasks(loop)
for task in tasks:
# print(f"Cancelling task {task}")
task.cancel()

loop.close()
2 changes: 0 additions & 2 deletions tests/api/pytest.ini

This file was deleted.

0 comments on commit 9b994a6

Please sign in to comment.