| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import traceback |
| 12 |
|
| 13 |
import pytest |
| 14 |
|
| 15 |
from hypothesis import Verbosity, given, settings, strategies as st |
| 16 |
|
| 17 |
|
| 18 |
@pytest.mark.parametrize("verbosity", [Verbosity.normal, Verbosity.debug]) |
| 19 |
@pytest.mark.parametrize("env_value", ["", "1"]) |
| 20 |
def test_tracebacks_omit_hypothesis_internals(monkeypatch, env_value, verbosity): |
| 21 |
monkeypatch.setenv("HYPOTHESIS_NO_TRACEBACK_TRIM", env_value) |
| 22 |
|
| 23 |
@settings(verbosity=verbosity) |
| 24 |
@given(st.just(False)) |
| 25 |
def simplest_failure(x): |
| 26 |
raise ValueError |
| 27 |
|
| 28 |
try: |
| 29 |
simplest_failure() |
| 30 |
except ValueError as e: |
| 31 |
tb = traceback.extract_tb(e.__traceback__) |
| 32 |
# Unless in debug mode, Hypothesis adds 1 frame - the least possible! |
| 33 |
# (4 frames: this one, simplest_failure, internal frame, assert False) |
| 34 |
if verbosity < Verbosity.debug and not env_value: |
| 35 |
assert len(tb) == 4 |
| 36 |
else: |
| 37 |
assert len(tb) >= 5 |