Py学习  »  pycharm

如何在PyCharm中运行Django unittests?

Dave • 4 年前 • 781 次点击  

我在PyCharm 2018.2.4中使用Python3.7,Django。我已经在PyCharm中加载了我的项目并打开了我的文件,/mainpage/tests.py,它是

from django.test import TestCase
from mainpage.models import ArticleStat, Article
import unittest


class TestModels(unittest.TestCase):

    fixtures = ['/mainpage/fixtures/test_data.yaml',]

    # Test saving an article stat that hasn't previously
    # existed
    def test_add_articlestat(self):
        id = 1
        article = Article.objects.filter(id=id)
        self.assertTrue(article, "A pre-condition of this test is that an article exist with id=" + str(id))
        articlestat = ArticleStat(article=article,elapsed_time_in_seconds=250,votes=25,comments=15)
        articlestat.save()
        article_stat = ArticleStat.objects.get(article=article)
        self.assertTrue(article_stat, "Failed to svae article stat properly.")

我想用PyCharm运行这个测试文件。我转到“Run”菜单并选择“rununittestsfortests.models”

Error running 'Unittests for tests.TestModels': Can't find file where tests.TestModels declared. Make sure it is in project roo

为了在IDE中运行测试,我需要在PyCharm中做什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53799
 
781 次点击