I would like to write a test case like:

    # Create fake request with missing header that we are testing for
    request = HttpRequest() 
    request.META = {}
    response = MyApp.views.start(request)
    self.assertEqual(400, response.status_code, "Unexpected response code")

When I run the above code I see the following error message:

AttributeError: 'module' object has no attribute 'views'

I am a Python newbie and am clearly doing this wrong. Can anyone point how what the error is?

Thanks. -Raj

有帮助吗?

解决方案

You haven't shown your imports, or included the full traceback, which makes it harder to work out what's going wrong.

Changing

import myapp

to

import myapp.views

might work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top