*OOPWBUJWFGFBUVSFT pYUVSFT QPXFSGVMQMVHJO TZTUFN w -PUTPGFYJTUJOHQMVHJOT w $PWFSBHF EJTUSJCVUFEUFTUJOH 1&1DIFDLJOH w %KBOHPQMVHJOQZUFTUEKBOHP w 8SJUFUFTUTJOBQZUIPOJDTUZMF
your/project/directory w $POpHVSFTFUUJOHT w 4FUDJANGO_SETTINGS_MODULEJOZPVSTIFMM w 03DSFBUFQZUFTUJOJBOETFU DJANGO_SETTINGS_MODULE=mysettings w #POVT3VO1ZUIPOTIFMMEJSFDUMZXJUIpython
specific file $ py.test tests/app/test_views.py # run test which matches tests named *test_foo* $ py.test tests/app/test_views.py -‐k test_foo # run all non database tests (more on this later) $ py.test tests/app -‐m 'not django_db'
# call code that uses settings.DATE_FORMAT ... # the settings will be automatically reset after this test def test_with_testclient(client): # client is an instance of Django's TestClient, just like # self.client in a Django TestCase response = client.get('/foo/bar') assert response.status_code == 200
user_in_db(db): # The db argument makes database access allowed return UserFactory.create() @pytest.mark.django_db def test_with_saved_user(user_in_db): # user_in_db is a saved user pass
W-7R#2D'NZX w $BSM.FZFS 5FTUJOHBOE%KBOHP 1Z$PO w "MPUPG%KBOHPUFTUJOHCFTUQSBDUJDFT w IUUQXXXZPVUVCFDPNXBUDI WJDL/2D/9J4 w QZUFTUEPDVNFOUBUJPO w IUUQQZUFTUPSH w QZUFTUEKBOHPEPDVNFOUBUJPO w IUUQQZUFTUEKBOHPSFBEUIFEPDTPSH