def test_invalid_glob_warns(tester, ext_tester, config): tester.useSafeMath(5, 10) ext_tester.makeExternalCall(tester, 5) config.settings["reports"]["exclude_paths"] = "/contracts" with pytest.warns(BrownieConfigWarning): _build_gas_profile_output()
def test_exclude_gas(tester, ext_tester, config): tester.useSafeMath(5, 10) ext_tester.makeExternalCall(tester, 5) report = _build_gas_profile_output() config.settings["reports"]["exclude_contracts"] = "ExternalCallTester" assert _build_gas_profile_output() != report
def test_exclude_gas_internal_calls_no_effect(tester, ext_tester, config): tester.useSafeMath(5, 10) ext_tester.makeExternalCall(tester, 5) report = _build_gas_profile_output() config.settings["reports"]["exclude_contracts"] = "SafeMath" assert _build_gas_profile_output() == report
def main(): args = docopt(__doc__, more_magic=True) _update_argv_from_docopt(args) active_project = None if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") network.connect(CONFIG.argv["network"]) path, _ = _get_path(args["<filename>"]) path_str = path.absolute().as_posix() try: return_value, frame = run( args["<filename>"], method_name=args["<function>"] or "main", args=args["<arg>"], _include_frame=True, ) exit_code = 0 except Exception as e: print(color.format_tb(e)) frame = next( (i.frame for i in inspect.trace()[::-1] if Path(i.filename).as_posix() == path_str), None, ) if frame is None: # exception was an internal brownie issue - do not open the console sys.exit(1) exit_code = 1 return_value = None try: if args["--interactive"]: # filter internal objects from the namespace prior to opening the console globals_dict = { k: v for k, v in frame.f_globals.items() if not k.startswith("__") } extra_locals = { "_": return_value, **globals_dict, **frame.f_locals } shell = Console(active_project, extra_locals) shell.interact( banner="\nInteractive mode enabled. Use quit() to close.", exitmsg="") finally: # the console terminates from a SystemExit - make sure we still deliver the final gas report if CONFIG.argv["gas"]: print("\n======= Gas profile =======") for line in _build_gas_profile_output(): print(line) sys.exit(exit_code)
def main(): args = docopt(__doc__) _update_argv_from_docopt(args) if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") else: raise ProjectNotFound network.connect(CONFIG.argv["network"]) path, _ = _get_path(args["<filename>"]) path_str = path.absolute().as_posix() try: run(args["<filename>"], method_name=args["<function>"] or "main") except Exception as e: print(color.format_tb(e)) if args["--interactive"]: frame = next( (i.frame for i in inspect.trace()[::-1] if Path(i.filename).as_posix() == path_str), None, ) if frame is not None: globals_dict = { k: v for k, v in frame.f_globals.items() if not k.startswith("__") } shell = Console(active_project, { **globals_dict, **frame.f_locals }) shell.interact( banner="\nInteractive mode enabled. Use quit() to close.", exitmsg="") sys.exit(1) if CONFIG.argv["gas"]: print("\n======= Gas profile =======") for line in _build_gas_profile_output(): print(line)
def pytest_terminal_summary(self, terminalreporter): """ Add a section to terminal summary reporting. When `--gas` is active, outputs the gas profile report. Arguments --------- terminalreporter : `_pytest.terminal.TerminalReporter` The internal terminal reporter object """ if CONFIG.argv["gas"]: terminalreporter.section("Gas Profile") for line in output._build_gas_profile_output(): terminalreporter.write_line(line) super().pytest_terminal_summary(terminalreporter)