Django test file


Django test file


In the process of developing projects with Django, developers will inevitably test their own code during development. How to test a py file in Django alone and how to write a test script?


Django automatically creates under the application when creating a project. This py file can be used as a test file; You can also manually create a py test file under the application. Either way, you need to write the following code in advance:

From django.test import testcase # does not need to be imported manually, and manually created test files need to be imported

import os

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
    import django
    #Now you can enter the test code

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]