What I’m trying to do:
run pytest locally while referencing anvil app client modules
What I’ve tried and what’s not working:
- Created a simple anvil app with a single form and a module. The module (named Core) has a portable class that looks like the following.
import anvil.server
@anvil.server.portable_class
class Asset():
def __init__(self, pn:str, sn:str):
self.pn = pn
self.sn = sn
- Created a virtual environment locally and installed pytest and anvil-client
- I pulled the code locally and added a tests/ directory to the root of the app.
- Added an initial test in the tests/ directory that referenced the class in the module
from client_code.Core import Asset
def test_core():
a = Asset('pn1234', sn='sn888')
assert a.pn == 'pn1234'
- Run pytest and get the following error:
ERROR collecting tests/test_anvil.py
ImportError while importing test module 'D:\projects\TestAnvil\tests\test_anvil.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Program Files\Python310\lib\importlib\__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\test_anvil.py:1: in <module>
from client_code.Core import Asset
E ModuleNotFoundError: No module named 'client_code'
I have tried various from/import formats, and sprinkled init.py in various places.
I’m sure I’m missing something simple to get this working