Visual Studio Test Explorer For Python Django Tests with Database Access

邮差的信 提交于 2019-12-14 01:25:54

问题


Starting test runs from Visual Studio Test Explorer doesn't call database creation and Django setup() before running the test(s).

My current workaround is to call something like this, which I keep in config.settings.test

def setUpTestingWithDatabase():
    import os
    from django.test.utils import setup_test_environment
    from django import setup
    os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.test"
    setup_test_environment()
    setup()

by adding this code to the top of every test file:

import sys
if not ('manage.py' in sys.argv):
    from config.settings.test import setUpTestingWithDatabase
    setUpTestingWithDatabase()

This works, and can still use the nose runner, and a CLI call like

> python manage.py test myApp

This works all very well, but I would like to avoid this code, keep it vanilla AND use it from both CLI and Test Explorer. MS Visual Studio supports runsettings, and I wonder if they can be used? Any other ideas?

来源:https://stackoverflow.com/questions/54494257/visual-studio-test-explorer-for-python-django-tests-with-database-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!