mercredi 5 août 2015

Testing threaded code in Django

I'm testing the Django views - a view, that contains a class in itself. Can anyone help me to solve this problem: how I can to mock class or another way to test this view, because without mocking I get the error: OperationalError: no such table: - as I understand the test database is empty in new thread(I use sqlite3 in-memory for testing), but I don't know how to solve this problem.

View:

def view(self):
    import threading

    class Fun(threading.Thread):
        def run(self):
            SomeModel.class_method() - this method remove and create SomeModel instances
    Fun().start()
    return render_to_response('some_html.html')

Aucun commentaire:

Enregistrer un commentaire