0

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 ======================================= 
5
  • 1
    Hi, can you please make this a minimalistic question? Right now it's sort of "can you debug my code". We strive to make the platform minimalistic questions that others will run into. What happens when you delete all the tests except that one? Feb 2, 2022 at 3:47
  • @PatrickCollins Oh sorry, I will make sure to make the questions smaller next time! When I remove all the tests except that one, it says "collected 0 items, no tests ran in 0.05s"
    – binoy john
    Feb 2, 2022 at 8:55
  • 1
    Can you update your question with this minimized code, the command you ran, and test file? Feb 2, 2022 at 14:25
  • I have updated the question. Please let me know if any other changes need to be made.
    – binoy john
    Feb 2, 2022 at 15:45
  • Ideally I'd like it smaller, but I'll answer below. Feb 2, 2022 at 20:24

1 Answer 1

1

Your functions must start with the test prefix.

can_start_and_enter_lottery -> test_can_start_and_enter_lottery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.