Skip to content

Commit

Permalink
feat: allow --show-internal to be configured and use in framework…
Browse files Browse the repository at this point in the history
…'s tests (#2417)
  • Loading branch information
antazoey authored Dec 17, 2024
1 parent ec381e7 commit 0f2b2f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[build-system]
requires = ["setuptools>=75.0.0", "wheel", "setuptools_scm[toml]>=5.0"]

[tool.ape.test]
show_internal = true

[tool.mypy]
exclude = ["build/", "dist/", "docs/", "tests/integration/cli/projects/"]
check_untyped_defs = true
Expand Down
2 changes: 1 addition & 1 deletion src/ape/pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def html_coverage(self) -> Union[bool, dict]:

@cached_property
def show_internal(self) -> bool:
return self.pytest_config.getoption("--show-internal")
return self.pytest_config.getoption("--show-internal") or self.ape_test_config.show_internal

@cached_property
def gas_exclusions(self) -> list["ContractFunctionPath"]:
Expand Down
6 changes: 6 additions & 0 deletions src/ape_test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ class ApeTestConfig(PluginConfig):
Settings for the provider.
"""

show_internal: bool = False
"""
Set to ``True`` to always show Ape's internal stack-trace in errors,
useful for debugging the framework itself.
"""

@field_validator("balance", mode="before")
@classmethod
def validate_balance(cls, value):
Expand Down
13 changes: 13 additions & 0 deletions tests/functional/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def test_balance_set_from_currency_str(self):


class TestConfigWrapper:
@pytest.mark.parametrize(
"cli_value,config_value", [(True, False), (False, True), (False, False)]
)
def test_show_internal(self, mocker, cli_value, config_value):
pytest_cfg = mocker.MagicMock()
ape_test_cfg = mocker.MagicMock()
wrapper = ConfigWrapper(pytest_cfg)
wrapper.__dict__["ape_test_config"] = ape_test_cfg
expected = cli_value or config_value # True if there is a True
pytest_cfg.getoption.return_value = cli_value
ape_test_cfg.show_internal = config_value
assert wrapper.show_internal is expected

def test_verbosity(self, mocker):
"""
Show it returns the same as pytest_config's.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cli/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_fails():
pytester.makepyfile(test)
stdin = "print(foo)\nexit\n"
monkeypatch.setattr("sys.stdin", io.StringIO(stdin))
result = pytester.runpytest("--interactive", "-s")
result = pytester.runpytest_subprocess("--interactive", "-s")
result.assert_outcomes(failed=1)
actual = str(result.stdout)
assert secret in actual
Expand Down

0 comments on commit 0f2b2f0

Please sign in to comment.