So I wanted to test my lottery contract and python scripts. I have three functions namely test_get_entrance_fee()
, test_cant_enter_unless_started()
and can_start_and_enter_lottery()
Out of these three, only test_get_entrance_fee()
and test_cant_enter_unless_started()
run properly and pass. However, the third function can_start_and_enter_lottery()
does not run, and gets deselected every time.
The following is my testing file code:
from brownie import Lottery, accounts, config, network, web3, exceptions
import pytest
from scripts.deploy_lottery import deploy_lottery
from web3 import Web3
from scripts.helpful_scripts import LOCAL_BLOCKCHAIN_ENVIRONMENTS, get_account
def test_get_entrance_fee():
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
lottery = deploy_lottery()
expected_entry_fee = Web3.toWei(0.025, "ether")
entrance_fee = lottery.getEntranceFee()
# assert
assert expected_entry_fee == entrance_fee
def test_cant_enter_unless_started():
account = get_account()
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
lottery = deploy_lottery()
fee = lottery.getEntranceFee() + 200
with pytest.raises(AttributeError):
lottery.enter({"from": account, "value": fee})
def can_start_and_enter_lottery():
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
lottery = deploy_lottery()
account = get_account()
fee = lottery.getEntranceFee() + 200
lottery.startLottery({"from": account})
lottery.enter({"from": account, "value": fee})
assert lottery.players(0) == account
The message displayed in the terminal after running brownie test
is as follows:
======================================== 2 passed in 5.45s =========================================
The message in the terminal after running brownie test -k can_start_and_enter_lottery()
is as follows :
collected 2 items / 2 deselected
====================================== 2 deselected in 0.02s =======================================