Files
pytest2/testing/test_scope.py
Pierre Sassoulas 4588653b24 Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff
ruff is faster and handle everything we had prior.

isort configuration done based on the indication from
https://github.com/astral-sh/ruff/issues/4670, previousely based on
reorder-python-import (#11896)

flake8-docstrings was a wrapper around pydocstyle (now archived) that
explicitly asks to use ruff in https://github.com/PyCQA/pydocstyle/pull/658.

flake8-typing-import is useful mainly for project that support python 3.7
and the one useful check will be implemented in https://github.com/astral-sh/ruff/issues/2302

We need to keep blacken-doc because ruff does not handle detection
of python code inside .md and .rst. The direct link to the repo is
now used to avoid a redirection.

Manual fixes:
- Lines that became too long
- % formatting that was not done automatically
- type: ignore that were moved around
- noqa of hard to fix issues (UP031 generally)
- fmt: off and fmt: on that is not really identical
  between black and ruff
- autofix re-order in pre-commit from faster to slower

Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-02-02 09:27:00 +01:00

40 lines
1.3 KiB
Python

import re
from _pytest.scope import Scope
import pytest
def test_ordering() -> None:
assert Scope.Session > Scope.Package
assert Scope.Package > Scope.Module
assert Scope.Module > Scope.Class
assert Scope.Class > Scope.Function
def test_next_lower() -> None:
assert Scope.Session.next_lower() is Scope.Package
assert Scope.Package.next_lower() is Scope.Module
assert Scope.Module.next_lower() is Scope.Class
assert Scope.Class.next_lower() is Scope.Function
with pytest.raises(ValueError, match="Function is the lower-most scope"):
Scope.Function.next_lower()
def test_next_higher() -> None:
assert Scope.Function.next_higher() is Scope.Class
assert Scope.Class.next_higher() is Scope.Module
assert Scope.Module.next_higher() is Scope.Package
assert Scope.Package.next_higher() is Scope.Session
with pytest.raises(ValueError, match="Session is the upper-most scope"):
Scope.Session.next_higher()
def test_from_user() -> None:
assert Scope.from_user("module", "for parametrize", "some::id") is Scope.Module
expected_msg = "for parametrize from some::id got an unexpected scope value 'foo'"
with pytest.raises(pytest.fail.Exception, match=re.escape(expected_msg)):
Scope.from_user("foo", "for parametrize", "some::id") # type:ignore[arg-type]