File: test_typer.py

package info (click to toggle)
sentry-python 2.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,268 kB
  • sloc: python: 58,847; sh: 126; makefile: 114; xml: 2
file content (52 lines) | stat: -rw-r--r-- 1,187 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
import subprocess
import sys
from textwrap import dedent
import pytest

from typer.testing import CliRunner

runner = CliRunner()


def test_catch_exceptions(tmpdir):
    app = tmpdir.join("app.py")

    app.write(
        dedent(
            """
    import typer
    from unittest import mock

    from sentry_sdk import init, transport
    from sentry_sdk.integrations.typer import TyperIntegration

    def capture_envelope(self, envelope):
        print("capture_envelope was called")
        event = envelope.get_event()
        if event is not None:
            print(event)

    transport.HttpTransport.capture_envelope = capture_envelope

    init("http://foobar@localhost/123", integrations=[TyperIntegration()])

    app = typer.Typer()

    @app.command()
    def test():
        print("test called")
        raise Exception("pollo")

    app()
    """
        )
    )

    with pytest.raises(subprocess.CalledProcessError) as excinfo:
        subprocess.check_output([sys.executable, str(app)], stderr=subprocess.STDOUT)

    output = excinfo.value.output

    assert b"capture_envelope was called" in output
    assert b"test called" in output
    assert b"pollo" in output