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

Correct frame for locals/globals with debugging console #523

Merged
merged 1 commit into from
May 16, 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
13 changes: 10 additions & 3 deletions brownie/test/managers/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,27 @@ def pytest_exception_interact(self, report, call):

tw = TerminalWriter()
report.longrepr.toterminal(tw)
location = report.location[0]

# find last traceback frame within the active test
traceback = next(
(i for i in call.excinfo.traceback[::-1] if i.path.strpath.endswith(location)),
call.excinfo.traceback[-1],
)

# get global namespace
globals_dict = call.excinfo.traceback[-1].frame.f_globals
globals_dict = traceback.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]]
test_names = self.node_map[location]
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 = traceback.locals
locals_dict = {k: v for k, v in locals_dict.items() if not k.startswith("@")}

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