forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_typer.py
More file actions
52 lines (37 loc) · 1.16 KB
/
Copy pathtest_typer.py
File metadata and controls
52 lines (37 loc) · 1.16 KB
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