File: test_scope.py

package info (click to toggle)
python-pytest-unmagic 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 172 kB
  • sloc: python: 1,199; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from .util import get_source, unmagic_tester


def test_no_active_session_error():
    @get_source
    def conftest():
        import pytest
        from unmagic.scope import get_active

        calls = []

        @pytest.hookimpl(tryfirst=True)
        def pytest_sessionstart(session):
            with pytest.raises(ValueError, match="no active pytest session"):
                print(get_active(session))
            calls.append("configure")

    @get_source
    def test_py():
        from conftest import calls

        def test():
            assert calls == ["configure"]

    pytester = unmagic_tester()
    pytester.makeconftest(conftest)
    pytester.makepyfile(test_py)

    result = pytester.runpytest("-s")
    result.assert_outcomes(passed=1)


def test_no_active_request_error():
    @get_source
    def conftest():
        import pytest
        from unmagic.scope import get_request

        calls = []

        def pytest_runtestloop():
            with pytest.raises(ValueError, match="no active request"):
                get_request()
            calls.append("run")

    @get_source
    def test_py():
        from conftest import calls

        def test():
            assert calls == ["run"]

    pytester = unmagic_tester()
    pytester.makeconftest(conftest)
    pytester.makepyfile(test_py)

    result = pytester.runpytest("-s")
    result.assert_outcomes(passed=1)