Skip to content

Commit

Permalink
Merge pull request #819 from eth-brownie/feat-pytest-network-connect
Browse files Browse the repository at this point in the history
Connect to network immediatly prior to running tests
  • Loading branch information
iamdefinitelyahuman committed Oct 22, 2020
2 parents c5595db + f81b08b commit 94d9f0c
Showing 1 changed file with 20 additions and 5 deletions.
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

0 comments on commit 94d9f0c

Please sign in to comment.