Import and unit tests best practices

48 views
Skip to first unread message

clement chesnin

unread,
Oct 13, 2023, 6:25:58 AM10/13/23
to py4web
Hello,

First, thanks for the good work with py4web.

I am currently playing with py4web, hoping to try and use it to migrate an old web2py app I should maintain in my job. Note that I am quite new to python, coming from C# and Java among others...

I tried to split my models and controllers, and add some doctests / unittests into it. I met with some issues with import quite soon :) As a consequence, I wonder :
- What are the best pratices for import management in a py4web app ? In examples, I see that relative imports are used, it it what should be used ?
- How do you deal with unit tests regarding to import ? I am struggling getting something to work, with ImportError: attempted relative import beyond top-level package. I somewhat get it to work with pytest, but not sure I get it right...
- How do you deal with unit tests regarding to db mocking ? Can I simply set up a DB copying my model, but independant from py4web DB ? run .sql or manually importing into it ? and make it work when testing my controllers ?

I understand that it is quite a lot of questions, but I'd like to start in the right direction from the start.

Regards,

Clément.

Jim Steil

unread,
Oct 13, 2023, 9:42:25 AM10/13/23
to py4web
following...
Reply all
Reply to author
Forward
0 new messages