【问题标题】:Unable to run Nosetests on classes or functions无法在类或函数上运行 Nosetests
【发布时间】:2017-02-16 16:25:51
【问题描述】:

我正在使用 pycharm 并尝试运行单个测试。我的“运行所有测试有效(使用 py.test),但我想运行特定测试。当我尝试运行 Nosetest 时,我收到此错误:

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我的 wsgi.py 看起来像这样:

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "v3.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()

【问题讨论】:

  • 您是否尝试过使用 py.test 运行特定测试? py.test [module_filepath]::[name_of_test](来源:doc.pytest.org/en/latest/usage.html)
  • 你的意思是在终端?像 python manage.py py.test [[module_filepath] : : [name_of_test]
  • 您的 wsgi 文件与运行测试无关。但是你至少需要展示你是如何配置你的测试的,以及你用来运行它们的命令。
  • @Marviel 您的示例适用于特定模块甚至测试类。 python -m pytest test_services.py::TestUpgradeToInvoice 但是也可以只测试函数吗?
  • @Marviel 我如何通知您的答案作为答案?

标签: python django unit-testing pycharm nose


【解决方案1】:

您是否尝试过使用 py.test 运行特定测试?在命令行上:

py.test [module_filepath]::[name_of_test]

在您的情况下,您可能正在尝试在类中运行一个函数,如下所示: py.test test_mod.py::TestClass::test_method

(来源:http://doc.pytest.org/en/latest/usage.html

(从 cmets 重新格式化,因此可以接受答案)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2015-01-17
    • 2012-05-08
    相关资源
    最近更新 更多