Skip to content

Commit

Permalink
Merge pull request #506 from iamdefinitelyahuman/feat-pytest-console-…
Browse files Browse the repository at this point in the history
…globals

feat: expose global namespace in pytest interactive console
  • Loading branch information
iamdefinitelyahuman authored May 9, 2020
2 parents 025329e + e85df15 commit 9e5ba42
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion brownie/test/managers/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,26 @@ def pytest_exception_interact(self, report, call):
tw = TerminalWriter()
report.longrepr.toterminal(tw)

# get global namespace
globals_dict = call.excinfo.traceback[-1].frame.f_globals

# filter python internals and pytest internals
globals_dict = {k: v for k, v in globals_dict.items() if not k.startswith("__")}
globals_dict = {k: v for k, v in globals_dict.items() if not k.startswith("@")}

# filter test functions
test_names = self.node_map[report.location[0]]
globals_dict = {k: v for k, v in globals_dict.items() if k not in test_names}

# get local namespace
locals_dict = call.excinfo.traceback[-1].locals
locals_dict = {k: v for k, v in locals_dict.items() if not k.startswith("@")}

namespace = {"_callinfo": call, **globals_dict, **locals_dict}

try:
CONFIG.argv["cli"] = "console"
shell = Console(self.project, extra_locals={"_callinfo": call, **locals_dict})
shell = Console(self.project, extra_locals=namespace)
shell.interact(
banner=f"\nInteractive mode enabled. Use quit() to continue running tests.",
exitmsg="",
Expand Down

0 comments on commit 9e5ba42

Please sign in to comment.