0

我正在根据参考资料学习可靠性(https://www.youtube.com/watch?v=M576WGiDBdQ&t=25510s

当我尝试在 Brownie 框架下编写运行测试时,遇到了一个错误,说找不到文件。

ganache-cli 工作正常。使用 Macbook Pro,英特尔不是 Apple M1 CPU。

寻求帮助。谢谢。

这是 brownie 测试文件夹中的测试脚本文件。

from brownie import SimpleStorage, accounts

# Arrange
account = accounts[0]
print(account)
# Act
simple_storage = SimpleStorage.deploy({"from": account})
starting_value = simple_storage.retrieve()
expected = 0
# Assert
assert starting_value == expected


错误消息。

(base) liwei@liweideMacBook-Pro Brownie_Simple_Storage % brownie run tests/test_simple_storage.py
Brownie v1.17.2 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.
Attached to local RPC client listening at '127.0.0.1:8545'...
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/run.py", line 46, in main
    path, _ = _get_path(args["<filename>"])
  File "brownie/project/scripts.py", line 130, in _get_path
    raise FileNotFoundError(f"Cannot find {path_str}")
FileNotFoundError: Cannot find tests/test_simple_storage.py
(base) liwei@liweideMacBook-Pro Brownie_Simple_Storage % 


这是 Brownie 脚本文件夹中的 deploy.py 文件

import os


def deploy_simple_storage():

    # load from you set encrypted , not from ganache-cli which is brownie automated connceted to
    # account = accounts.load("MG515-account")
    # print(account)

    # add private key use enviroment variables
    # account = accounts.add(os.getenv("PRIVATE_KEY"))
    # print(account)

    # .deploy() , always need a "from"key in a dictinary when making a transaction
    account = accounts.add(config["wallets"]["from_key"])
    simple_storage = SimpleStorage.deploy({"from": account})
    stored_value = simple_storage.retrieve()
    print("Current stored value is :&quot;)
    print(stored_value)
    print("Updating Contract...")
    transaction = simple_storage.store(15, {"from": account})
    transaction.wait(1)
    updated_store_value = simple_storage.retrieve()
    print("Current stored value is :&quot;)
    print(updated_store_value)


def main():
    deploy_simple_storage()

4

1 回答 1

0

你检查过你的文件路径和文件名吗?

FileNotFoundError: Cannot find tests/test_simple_storage.py

应该有tests文件夹和名为 test_simple_storage.py 的测试脚本文件。

于 2022-01-06T06:39:25.470 回答