Skip to content

Commit

Permalink
Fix pytest warnings, move event_loop to conftest.py (#231)
Browse files Browse the repository at this point in the history
* add pytest asyncio mode

* add event loop

* remove unnecessary event loops

* add line

* fix line
  • Loading branch information
andrew-fleming authored Mar 25, 2022
1 parent 574bc03 commit 118f41f
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 111 deletions.
7 changes: 1 addition & 6 deletions tests/access/test_Ownable.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import Signer, contract_path

signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()
signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
Expand Down
7 changes: 1 addition & 6 deletions tests/account/test_Account.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from starkware.starkware_utils.error_handling import StarkException
from starkware.starknet.definitions.error_codes import StarknetErrorCode
from utils import Signer, assert_revert, contract_path


signer = Signer(123456789987654321)
other = Signer(987654321123456789)

IACCOUNT_ID = 0xf10dbd44
TRUE = 1


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
async def account_factory():
starknet = await Starknet.empty()
Expand Down
7 changes: 1 addition & 6 deletions tests/account/test_AddressRegistry.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import Signer, contract_path


signer = Signer(123456789987654321)
L1_ADDRESS = 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984
ANOTHER_ADDRESS = 0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
async def account_factory():
starknet = await Starknet.empty()
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest
import asyncio

@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()
8 changes: 2 additions & 6 deletions tests/introspection/test_ERC165.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import assert_revert, contract_path


# interface ids
ERC165_ID = 0x01ffc9a7
INVALID_ID = 0xffffffff
OTHER_ID = 0x12345678


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
async def erc165_factory():
starknet = await Starknet.empty()
Expand Down
6 changes: 0 additions & 6 deletions tests/security/test_safemath.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
MAX_UINT256, assert_revert, add_uint, sub_uint,
mul_uint, div_rem_uint, to_uint, contract_path
)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
async def safemath_mock():
starknet = await Starknet.empty()
Expand Down
7 changes: 1 addition & 6 deletions tests/token/erc20/test_ERC20.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, uint, str_to_felt, MAX_UINT256, INVALID_UINT256, ZERO_ADDRESS,
assert_event_emitted, assert_revert, sub_uint, add_uint, contract_path
)

signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()
signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
Expand Down
6 changes: 1 addition & 5 deletions tests/token/erc20/test_ERC20_Burnable_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
contract_path
)

signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()
signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
Expand Down
6 changes: 0 additions & 6 deletions tests/token/erc20/test_ERC20_Mintable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, uint, str_to_felt, MAX_UINT256, ZERO_ADDRESS, INVALID_UINT256,
Expand All @@ -12,11 +11,6 @@
RECIPIENT = 789


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
async def token_factory():
starknet = await Starknet.empty()
Expand Down
7 changes: 1 addition & 6 deletions tests/token/erc20/test_ERC20_Pausable.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import Signer, uint, str_to_felt, assert_revert, contract_path

signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()
signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
Expand Down
22 changes: 2 additions & 20 deletions tests/token/erc20/test_ERC20_Upgradeable.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, to_uint, sub_uint, str_to_felt, assert_revert,
get_contract_def, cached_contract, assert_event_emitted
get_contract_def, cached_contract
)


signer = Signer(123456789987654321)

USER = 999
Expand All @@ -16,24 +16,6 @@
DECIMALS = 18


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


# random value
VALUE = 123
VALUE_2 = 987


signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
7 changes: 1 addition & 6 deletions tests/token/erc721/test_ERC721_Mintable_Burnable.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, str_to_felt, ZERO_ADDRESS, TRUE, FALSE, assert_revert, INVALID_UINT256,
assert_event_emitted, get_contract_def, cached_contract, to_uint, sub_uint, add_uint
)


signer = Signer(123456789987654321)

NONEXISTENT_TOKEN = to_uint(999)
Expand All @@ -29,11 +29,6 @@
UNSUPPORTED_ID = 0xabcd1234


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
8 changes: 1 addition & 7 deletions tests/token/erc721/test_ERC721_Mintable_Pausable.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, str_to_felt, TRUE, FALSE, get_contract_def, cached_contract, assert_revert, to_uint
)

signer = Signer(123456789987654321)

signer = Signer(123456789987654321)

# random token IDs
TOKENS = [to_uint(5042), to_uint(793)]
Expand All @@ -15,11 +14,6 @@
DATA = [0x42, 0x89, 0x55]


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
7 changes: 1 addition & 6 deletions tests/token/erc721/test_ERC721_SafeMintable_mock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, str_to_felt, ZERO_ADDRESS, INVALID_UINT256, assert_revert,
assert_event_emitted, get_contract_def, cached_contract, to_uint
)


signer = Signer(123456789987654321)

# random token id
Expand All @@ -14,11 +14,6 @@
DATA = [0x42, 0x89, 0x55]


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, str_to_felt, MAX_UINT256, get_contract_def, cached_contract,
TRUE, assert_revert, to_uint, sub_uint, add_uint
)


signer = Signer(123456789987654321)

# random token IDs
Expand All @@ -22,11 +22,6 @@
ENUMERABLE_INTERFACE_ID = 0x780e9d63


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
7 changes: 1 addition & 6 deletions tests/upgrades/test_Proxy.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, assert_revert, get_contract_def, cached_contract
)


# random value
VALUE = 123

signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
8 changes: 1 addition & 7 deletions tests/upgrades/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import pytest
import asyncio
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, assert_revert, assert_event_emitted, get_contract_def, cached_contract
)


# random value
VALUE_1 = 123
VALUE_2 = 987


signer = Signer(123456789987654321)


@pytest.fixture(scope='module')
def event_loop():
return asyncio.new_event_loop()


@pytest.fixture(scope='module')
def contract_defs():
account_def = get_contract_def('openzeppelin/account/Account.cairo')
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ deps =
commands =
python -m build . -o dist
python -m twine check --strict dist/*

[pytest]
asyncio_mode=auto

0 comments on commit 118f41f

Please sign in to comment.