The error occurs because pytest
does not automatically set the Frappe application context as the bench run-tests
command does. To fix this, what you can do is manually initialize the Frappe context in your tests by using pytest
fixtures. Set up the context with frappe.init()
and frappe.connect()
before running the test, and clean up afterward with frappe.destroy()
. What this does is that it ensures that the necessary application context is available during test execution. Also make sure to apply patches correctly, as incorrect patching can also cause issues.