Debian Codegraph @

testing/test_scope.py

raw
1 from __future__ import annotations
2
3 import re
4
5 from _pytest.scope import Scope
6 import pytest
7
8
9 def test_ordering() -> None:
10 assert Scope.Session > Scope.Package
11 assert Scope.Package > Scope.Module
12 assert Scope.Module > Scope.Class
13 assert Scope.Class > Scope.Function
14
15
16 def test_next_lower() -> None:
17 assert Scope.Session.next_lower() is Scope.Package
18 assert Scope.Package.next_lower() is Scope.Module
19 assert Scope.Module.next_lower() is Scope.Class
20 assert Scope.Class.next_lower() is Scope.Function
21
22 with pytest.raises(ValueError, match="Function is the lower-most scope"):
23 Scope.Function.next_lower()
24
25
26 def test_next_higher() -> None:
27 assert Scope.Function.next_higher() is Scope.Class
28 assert Scope.Class.next_higher() is Scope.Module
29 assert Scope.Module.next_higher() is Scope.Package
30 assert Scope.Package.next_higher() is Scope.Session
31
32 with pytest.raises(ValueError, match="Session is the upper-most scope"):
33 Scope.Session.next_higher()
34
35
36 def test_from_user() -> None:
37 assert Scope.from_user("module", "for parametrize", "some::id") is Scope.Module
38
39 expected_msg = "for parametrize from some::id got an unexpected scope value 'foo'"
40 with pytest.raises(pytest.fail.Exception, match=re.escape(expected_msg)):
41 Scope.from_user("foo", "for parametrize", "some::id") # type:ignore[arg-type]