首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >py.test只找到5项,但我的类有更多

py.test只找到5项,但我的类有更多
EN

Stack Overflow用户
提问于 2013-10-15 11:21:51
回答 1查看 109关注 0票数 1

我对测试很陌生,所以我可能做错了什么。

我刚刚开始为我的项目编写一些测试,一切都进行得很顺利,直到py.test停止识别我编写的任何测试。

我的意思是,有5个以上的防御,但每次我运行,它只检查5个项目。

知道为什么吗?

py.test

代码语言:javascript
复制
[itxaka@optimus tests]$ py.test-2.7 
test session starts 
platform linux2 -- Python 2.7.5 -- pytest-2.4.2
collected 5 items 

gitlab_test.py .....
5 passed in 3.37 seconds 

使用setup.py方法

代码语言:javascript
复制
[itxaka@optimus i-python-gitlab]$ python2 setup.py test
running test
running egg_info
writing requirements to pyapi_gitlab.egg-info/requires.txt
writing pyapi_gitlab.egg-info/PKG-INFO
writing top-level names to pyapi_gitlab.egg-info/top_level.txt
writing dependency_links to pyapi_gitlab.egg-info/dependency_links.txt
reading manifest file 'pyapi_gitlab.egg-info/SOURCES.txt'
writing manifest file 'pyapi_gitlab.egg-info/SOURCES.txt'
running build_ext
testbadlogin (tests.gitlab_test.GitlabTest) ... ok
testcurrentuser (tests.gitlab_test.GitlabTest) ... ok
testgetusers (tests.gitlab_test.GitlabTest) ... ok
testlogin (tests.gitlab_test.GitlabTest) ... ok
testsshkeys (tests.gitlab_test.GitlabTest) ... ok

----------------------------------------------------------------------
Ran 5 tests in 3.070s

OK

代码

代码语言:javascript
复制
import unittest
import gitlab

user = ""
password = ""
host = ""
key = ""
git = gitlab.Gitlab(host=host, user=user)


class GitlabTest(unittest.TestCase):
    def testlogin(self):
        """
        Test to see if login works with proper credentials
        """
        self.assertTrue(git.login(user=user, password=password))

    def testbadlogin(self):
        """
        Test to see if login fails with no credentials
        """
        self.assertFalse(git.login("", ""))

    def testgetusers(self):
        git.login(user=user, password=password)
        # get all users
        assert isinstance(git.getusers(), list)  # compatible with 2.6
        self.assertTrue(git.getusers())
        # get X pages
        assert isinstance(git.getusers(page=2), list)  # compatible with 2.6
        assert isinstance(git.getusers(per_page=4), list)  # compatible with 2.6
        self.assertEqual(git.getusers(page=800), list(""))  # check against empty list
        self.assertTrue(git.getusers(per_page=43))  # check against false

    def testcurrentuser(self):
        git.login(user=user, password=password)
        assert isinstance(git.currentuser(), dict)  # compatible with 2.6
        self.assertTrue(git.currentuser())

    def addremoveuserstest(self):
        git.login(user=user, password=password)
        newuser = git.createuser("Test", "test", "123456",
                                 "test@test.com", "skype",
                                 "linkedin", "twitter", "25",
                                 bio="bio")
        assert isinstance(newuser, dict)
        # this below doesn't really matter. Gilab always answers a 404
        self.assertTrue(git.edituser(newuser['id'], twitter="tweeeeet", skype="Microsoft", username="Changed"))
        self.assertTrue(git.deleteuser(newuser['id']))

    def testsshkeys(self):
        git.login(user=user, password=password)
        git.addsshkey(title="test key", key=key)
        assert isinstance(git.getsshkeys(), list)  # compatible with 2.6
        # pass the id of the first key
        assert isinstance(git.getsshkey(id_=git.getsshkeys()[0]['id']), dict)  # compatible with 2.6
        self.assertTrue(git.getsshkey(id_=git.getsshkeys()[0]['id']))
        self.assertTrue(git.deletesshkey(id_=git.getsshkeys()[0]['id']))
        self.assertTrue(git.addsshkey(title="test key", key=key))
        self.assertTrue(git.deletesshkey(id_=git.getsshkeys()[0]['id']))
        self.assertTrue(git.addsshkeyuser(id_=git.currentuser()['id'], title="tests key", key=key))
        self.assertTrue(git.deletesshkey(id_=git.getsshkeys()[0]['id']))

    def projecttest(self):
        git.login(user=user, password=password)
        # we won't test the creation of the project as there is no way of deleting it trougth the api
        # so we would end with a million test projects. Next Gitlab version allows to delete projects
        #self.assertTrue(git.createproject("Test-pyapy-gitlab"))
        assert isinstance(git.getprojects(), list)
        assert isinstance(git.getprojects(page=5), list)
        assert isinstance(git.getprojects(per_page=7), list)
        assert isinstance(git.getproject(git.getprojects()[0]['id']), dict)
        self.assertFalse(git.getproject("wrong"))
        assert isinstance(git.getprojectevents(git.getprojects()[0]['id']), list)
        assert isinstance(git.getprojectevents(git.getprojects()[0]['id'], page=3), list)
        assert isinstance(git.getprojectevents(git.getprojects()[0]['id'], per_page=4), list)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-15 11:28:46

AFAIK,它只会将那些具有名称实际上以"test“开头的测试方法(通常,您会发现人们使用"test_”来表示清楚)。在这种精神下重新命名“最突出的”和“最高级的用户”应该会有所帮助。(有关此行为,请参见http://docs.python.org/dev/library/unittest.html。)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19379978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档