Search code examples
djangodjango-testingdjango-tests

Cant trigger a view's breakpoint in django tests


I want to debug a view that gets triggered inside a django tests.py Here's the view code:

def test_view(request):
    if request.method == "POST":
        with open("a_path_to_the_file/aaa.txt", "w") as f:
            f.write("done!")

Here's the test:

class ViewsTests(TestCase):
    def test_add_address(self):
        self.client.post(reverse("address_book:test_view"))

The view just doesn't run in that way. I want the file to be created after I run the test. The breakpoint is set on the if request.method == "POST": line. I use pycharm and run tests via pycharnm run config.


Solution

  • Got it guys! I had to add "test_server" to the ALLOWED_HOSTS list in the settings.py