From a6b9b248ad6a75bda0dfa318d8d8dd03e0f4af68 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Thu, 14 May 2020 17:59:41 +0400 Subject: [PATCH 1/2] fix: close all open projects when testing is complete --- brownie/test/fixtures.py | 3 --- brownie/test/managers/master.py | 5 ++++- brownie/test/managers/runner.py | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/brownie/test/fixtures.py b/brownie/test/fixtures.py index 0112401f5..ffd27257b 100644 --- a/brownie/test/fixtures.py +++ b/brownie/test/fixtures.py @@ -101,9 +101,6 @@ def package_loader(project_id): yield package_loader - for project in _open_projects.values(): - project.close(raises=False) - @pytest.fixture def no_call_coverage(self): """ diff --git a/brownie/test/managers/master.py b/brownie/test/managers/master.py index 405f84b0c..e083a1c4d 100644 --- a/brownie/test/managers/master.py +++ b/brownie/test/managers/master.py @@ -6,6 +6,7 @@ from xdist.scheduler import LoadFileScheduling from brownie._config import CONFIG +from brownie.project import get_loaded_projects from brownie.test import coverage from .base import PytestBrownieBase @@ -44,4 +45,6 @@ def pytest_sessionfinish(self, session): json.dump(report, fp, indent=2, sort_keys=True, default=sorted) coverage_eval = coverage.get_merged_coverage_eval(report["tx"]) self._sessionfinish_coverage(coverage_eval) - self.project.close() + + for project in get_loaded_projects(): + project.close(raises=False) diff --git a/brownie/test/managers/runner.py b/brownie/test/managers/runner.py index 672bad855..00759d256 100644 --- a/brownie/test/managers/runner.py +++ b/brownie/test/managers/runner.py @@ -285,7 +285,9 @@ def _sessionfinish(self, path): json.dump(report, fp, indent=2, sort_keys=True, default=sorted) coverage_eval = coverage.get_merged_coverage_eval() self._sessionfinish_coverage(coverage_eval) - self.project.close() + + for project in brownie.project.get_loaded_projects(): + project.close(raises=False) class PytestBrownieXdistRunner(PytestBrownieRunner): From 135b7c508e2afe5c61fe4d2ec176f2ec26aea22e Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Thu, 14 May 2020 19:20:30 +0400 Subject: [PATCH 2/2] fix: improve isolation fixture relocation logic --- brownie/test/managers/runner.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/brownie/test/managers/runner.py b/brownie/test/managers/runner.py index 00759d256..6cbdabaa4 100644 --- a/brownie/test/managers/runner.py +++ b/brownie/test/managers/runner.py @@ -19,14 +19,18 @@ from .base import PytestBrownieBase from .utils import convert_outcome +SCOPE_ORDER = ("session", "package", "module", "class", "function") + def _make_fixture_execute_first(metafunc, name, scope): fixtures = metafunc.fixturenames + + scopes = SCOPE_ORDER[SCOPE_ORDER.index(scope) :] if name in fixtures: fixtures.remove(name) defs = metafunc._arg2fixturedefs idx = next( - (fixtures.index(i) for i in fixtures if i in defs and defs[i][0].scope == scope), + (fixtures.index(i) for i in fixtures if i in defs and defs[i][0].scope in scopes), len(fixtures), ) fixtures.insert(idx, name)