Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to network immediatly prior to running tests #819

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions brownie/test/managers/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ def pytest_collection_modifyitems(self, items):
tests[path][0].parent.add_marker("skip")
self.isolated[path] = set(self.tests[path]["isolated"])

# only connect to network if there are tests to run
to_run = any(i for i in items if not i.get_closest_marker("skip"))
if to_run and not self.config.getoption("--fixtures"):
brownie.network.connect(CONFIG.argv["network"])

def _check_updated(self, path):
path = self._path(path)
if path not in self.tests or not self.tests[path]["isolated"]:
Expand All @@ -216,6 +211,26 @@ def _make_nodemap(self, ids):
path, test = self._test_id(item)
self.node_map.setdefault(path, []).append(test)

@pytest.hookimpl(trylast=True, hookwrapper=True)
def pytest_collection_finish(self, session):
"""
Called after collection has been performed and modified.

This is the final hookpoint that executes prior to running tests. If
the number of tests collected is > 0 and there is not an active network
at this point, Brownie connects to the the default network and launches
the RPC client if required.

Arguments
---------
session : pytest.Session
The pytest session object.
"""
outcome = yield
# handled as a hookwrapper to ensure connecting is the last action for this hook
if not outcome.get_result() and session.items and not brownie.network.is_connected():
brownie.network.connect(CONFIG.argv["network"])

def pytest_runtest_protocol(self, item):
"""
Implements the runtest_setup/call/teardown protocol for the given test item,
Expand Down