'AttributeError: 'NoneType' object has no attribute '_with_attr' Brownie

I was following the freecodecamp smart contract course, i was in lesson 6 brownie Fund me/ when i was setting up my test it showed me the next error:

platform win32 -- Python 3.10.2, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: C:\Users\kopid\brownie_fund_me
plugins: eth-brownie-1.16.4, hypothesis-6.21.6, forked-1.3.0, xdist-1.34.0, web3-5.23.1
collected 2 items

Launching 'ganache-cli.cmd --accounts 10 --hardfork istanbul --gasLimit 12000000 --mnemonic brownie --port 8545'...

tests\test_fund_me.py .F                                                                                                                                [100%]

========================================================================== FAILURES ========================================================================== 
________________________________________________________________ test_only_owner_can_withdraw ________________________________________________________________ 

    def test_only_owner_can_withdraw():
        if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
            pytest.skip("only for local testing")
        fund_me = deploy_fund_me()
        bad_actor = accounts.add()
        with pytest.raises(exceptions.VirtualMachineError):
>           fund_me.withdraw({"from": bad_actor})

tests\test_fund_me.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
..\AppData\Roaming\Python\Python310\site-packages\brownie\network\contract.py:1693: in __call__
    return self.transact(*args)
..\AppData\Roaming\Python\Python310\site-packages\brownie\network\contract.py:1566: in transact
    return tx["from"].transfer(
..\AppData\Roaming\Python\Python310\site-packages\brownie\network\account.py:680: in transfer
    receipt._raise_if_reverted(exc)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

self = <Transaction '0x63305841a2be302452e87ea2a87eba05918dc803a7be60da1c0ddaa29930f7a4'>, exc = None

    def _raise_if_reverted(self, exc: Any) -> None:
        if self.status or CONFIG.mode == "console":
            return
        if not web3.supports_traces:
            # if traces are not available, do not attempt to determine the revert reason
            raise exc or ValueError("Execution reverted")

        if self._dev_revert_msg is None:
            # no revert message and unable to check dev string - have to get trace
            self._expand_trace()
        if self.contract_address:
            source = ""
        elif CONFIG.argv["revert"]:
            source = self._traceback_string()
        else:
            source = self._error_string(1)
            contract = state._find_contract(self.receiver)
            if contract:
                marker = "//" if contract._build["language"] == "Solidity" else "#"
                line = self._traceback_string().split("\n")[-1]
                if marker + " dev: " in line:
                    self._dev_revert_msg = line[line.index(marker) + len(marker) : -5].strip()

>       raise exc._with_attr(
            source=source, revert_msg=self._revert_msg, dev_revert_msg=self._dev_revert_msg
        )
E       AttributeError: 'NoneType' object has no attribute '_with_attr'

..\AppData\Roaming\Python\Python310\site-packages\brownie\network\transaction.py:420: AttributeError
-------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------- 
the active network is: development
deploying Mocks....
Mocks are now Deployed
Contract deployed to 0xe0aA552A10d7EC8760Fc6c246D391E698a82dDf9
mnemonic: 'first rather school desert dish hole bar can wagon dinner black abuse'
================================================================== short test summary info =================================================================== 
FAILED tests/test_fund_me.py::test_only_owner_can_withdraw - AttributeError: 'NoneType' object has no attribute '_with_attr'
================================================================ 1 failed, 1 passed in 5.41s ================================================================= 
Terminating local RPC client...

any idea if the problem was with the code or is it something in brownie?



Solution 1:[1]

  1. Check if your deploy_fund_me method returns object correctly.

  2. Maybe you're using Brownie with old versions (e.g. 1.16). You can upgrade to latest version (currently 1.18.1). One of solutions to upgrade is following steps:

    2.1. Run pip uninstall eth-brownie

    2.2. Clone brownie from https://github.com/eth-brownie/brownie.git

    2.3. Go to cloned folder, run $python setup.py install

After checking the version of Brownie is upgrade, you can run the test again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tuq