Skip to content

Commit

Permalink
Merge branch 'main' into feat/provider-name-defined-at-cls
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Dec 19, 2024
2 parents 51ed55b + 443455b commit 72902f2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/ape/pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def html_coverage(self) -> Union[bool, dict]:
def show_internal(self) -> bool:
return self.pytest_config.getoption("--show-internal") or self.ape_test_config.show_internal

@cached_property
def enable_fixture_rebasing(self) -> bool:
return self.ape_test_config.enable_fixture_rebasing

@cached_property
def gas_exclusions(self) -> list["ContractFunctionPath"]:
"""
Expand Down
5 changes: 5 additions & 0 deletions src/ape/pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def add_fixture_info(self, name: str, **info):
def _get_cached_fixtures(self, nodeid: str) -> Optional["FixtureMap"]:
return self._nodeid_to_fixture_map.get(nodeid)

def needs_rebase(self, new_fixtures: list[str], snapshot: "Snapshot") -> bool:
return self.config_wrapper.enable_fixture_rebasing and bool(
new_fixtures and snapshot.fixtures
)

def rebase(self, scope: Scope, fixtures: "FixtureMap"):
if not (rebase := self._get_rebase(scope)):
# Rebase avoided: nothing would change.
Expand Down
3 changes: 1 addition & 2 deletions src/ape/pytest/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def _setup_isolation(self, item):

# Rebase if there are new fixtures found of non-function scope.
# And there are stateful fixtures of lower scopes that need resetting.
may_need_rebase = bool(new_fixtures and snapshot.fixtures)
if may_need_rebase:
if self.fixture_manager.needs_rebase(new_fixtures, snapshot):
self.fixture_manager.rebase(scope, fixtures)

# Append these fixtures so we know when new ones arrive
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 @@ -128,6 +128,12 @@ class ApeTestConfig(PluginConfig):
Configuration related to coverage reporting.
"""

enable_fixture_rebasing: bool = True
"""
Set to ``False`` to ignore fixture rebasing when non-function
scoped fixtures become invalidated.
"""

disconnect_providers_after: bool = True
"""
Set to ``False`` to keep providers connected at the end of the test run.
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ def test_is_stateful_when_not_using_test_provider(self, networks, fixture_manage
networks.active_provider = provider
assert actual is None

def test_needs_rebase(self, mocker, fixture_manager):
new_fixtures = ["new_fixture_1"]
snapshot = mocker.MagicMock()
actual = fixture_manager.needs_rebase(new_fixtures, snapshot)
assert actual

# Show you can disable fixture-rebasing.
original_value = fixture_manager.config_wrapper.__dict__.pop(
"enable_fixture_rebasing", True
)
fixture_manager.config_wrapper.__dict__["enable_fixture_rebasing"] = False
actual = fixture_manager.needs_rebase(new_fixtures, snapshot)

# (put back)
fixture_manager.config_wrapper.__dict__["enable_fixture_rebasing"] = original_value

assert not actual

def test_rebase(self, mocker, fixture_manager, fixture_map, create_fixture_info):
# We must have already started our module-scope isolation.
isolation_manager = IsolationManager(fixture_manager.config_wrapper, mocker.MagicMock())
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/cli/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest

from ape.logging import logger
from ape.pytest.fixtures import PytestApeFixtures
from tests.conftest import GETH_URI, geth_process_test
from tests.integration.cli.utils import skip_projects_except
Expand Down Expand Up @@ -178,10 +179,9 @@ def test_test(setup_pytester, integ_project, pytester, eth_tester_provider):
_ = eth_tester_provider # Ensure using EthTester for this test.
passed, failed = setup_pytester(integ_project)

from ape.logging import logger
with logger.at_level("DEBUG"):
result = pytester.runpytest_subprocess(timeout=120)

logger.set_level("DEBUG")
result = pytester.runpytest_subprocess(timeout=120)
outcomes = result.parseoutcomes()
assert "failed" not in outcomes if failed == 0 else outcomes["failed"] == failed
if integ_project.name != "test":
Expand Down

0 comments on commit 72902f2

Please sign in to comment.