Plugin test failure


#1

Hi all,
I’m writing a create/edit/delete test for a newly created object in a plugin.
I am trying to get the list of the existing objects, but I always got an empty list… but the records are there, correctly saved in my new table in the DB.
This is the code:

def test_obj:
    objs = obj.query.order_by(obj.id).all()

… but it is always returned as []
What am I doing wrong? Is there any ‘context’ I need to add?
Thank you,

Giorgio


#2

Did you create the records while running the tests? Tests never use your normal database, so anything you want in the DB for tests needs to be added (e.g. in the test itself or in a fixture used by the test).


#3

Alright, I didn’t know that! :slight_smile:
So it’s ok. I’ll populate the test DB at the beginning of the test script then.
Thank you!

Giorgio


#4

Yes, simply add a pytest fixture for it and enable it for the tests that need it.