Skip to content

Commit 7c8b50e

Browse files
committed
fix: format
1 parent dc9abbe commit 7c8b50e

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

posthog/test/test_exception_capture.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,40 @@ def process_data():
213213
with pytest.raises(subprocess.CalledProcessError) as excinfo:
214214
subprocess.check_output([sys.executable, str(app)], stderr=subprocess.STDOUT)
215215

216-
output = excinfo.value.output.decode('utf-8')
216+
output = excinfo.value.output.decode("utf-8")
217217

218218
assert "ZeroDivisionError" in output
219219
assert "code_variables" in output
220-
220+
221221
captured_vars = []
222-
for var_name in ['var_a', 'var_b', 'var_c', 'var_d', 'var_e',
223-
'var_f', 'var_g', 'var_h', 'var_i', 'var_j',
224-
'var_k', 'var_l', 'var_m', 'var_n', 'var_o',
225-
'var_p', 'var_q', 'var_r', 'var_s', 'var_t', 'var_u']:
222+
for var_name in [
223+
"var_a",
224+
"var_b",
225+
"var_c",
226+
"var_d",
227+
"var_e",
228+
"var_f",
229+
"var_g",
230+
"var_h",
231+
"var_i",
232+
"var_j",
233+
"var_k",
234+
"var_l",
235+
"var_m",
236+
"var_n",
237+
"var_o",
238+
"var_p",
239+
"var_q",
240+
"var_r",
241+
"var_s",
242+
"var_t",
243+
"var_u",
244+
]:
226245
if f"'{var_name}'" in output:
227246
captured_vars.append(var_name)
228-
229-
assert len(captured_vars) > 0, "Should capture at least some variables"
230-
assert len(captured_vars) < 21, f"Should not capture all 21 variables due to 20KB size limit (each truncated to 1024 chars = 21KB total), but got {len(captured_vars)}: {captured_vars}"
231-
232-
print(f"Captured {len(captured_vars)} variables: {captured_vars}")
247+
248+
assert len(captured_vars) > 0
249+
assert len(captured_vars) < 21
233250

234251

235252
def test_code_variables_disabled_capture(tmpdir):
@@ -264,7 +281,7 @@ def trigger_error():
264281
with pytest.raises(subprocess.CalledProcessError) as excinfo:
265282
subprocess.check_output([sys.executable, str(app)], stderr=subprocess.STDOUT)
266283

267-
output = excinfo.value.output.decode('utf-8')
284+
output = excinfo.value.output.decode("utf-8")
268285

269286
assert "ZeroDivisionError" in output
270287
assert "'code_variables':" not in output
@@ -308,7 +325,7 @@ def process_data():
308325
with pytest.raises(subprocess.CalledProcessError) as excinfo:
309326
subprocess.check_output([sys.executable, str(app)], stderr=subprocess.STDOUT)
310327

311-
output = excinfo.value.output.decode('utf-8')
328+
output = excinfo.value.output.decode("utf-8")
312329

313330
assert "ZeroDivisionError" in output
314331
assert "'code_variables':" not in output

test2.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from posthog import Posthog
2+
3+
posthog = Posthog(
4+
"phc_J1o2BXYxzXBHJeG2mS5hk62ijkTWk38Z385lO0MhU5w",
5+
host="http://localhost:8010",
6+
debug=True,
7+
enable_exception_autocapture=True,
8+
capture_exception_code_variables=True,
9+
)
10+
11+
12+
def intermediate_function():
13+
something_intermediate = "something_intermediate"
14+
process()
15+
16+
17+
def process():
18+
count = 100
19+
name = "test_user"
20+
active = False
21+
config = {"timeout": 30, "retries": 3}
22+
api_key = "123456789"
23+
24+
raise ValueError("Invalid configuration detected 2")
25+
26+
27+
intermediate_function()

0 commit comments

Comments
 (0)