鼻子测试和覆盖脚本

2024-04-25 01:13:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着运行nosetests和coverage,看看我的测试在一个小组项目中是否正常工作。当我运行时,虽然覆盖率仍然是0%,我想知道为什么。我尝试将test类更改为TestSteam,因为这样会有所帮助,但似乎不起作用:

脚本代码(hackathon/scripts)/蒸汽.py)地址:

def gamespulling(steamID,key):
    # Returns the XML data from the Steam API based of one's Steam ID number and returns a dictionary of gameids and minutes played.
    steaminfo = {'key': key, 'steamid': steamID,'format':'JSON','include_appinfo':'1'}
    r = requests.get('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/',params=steaminfo)  
    d = json.loads(r.content)
    # print d['response']['games']
    # print r.json()
    return d['response']['games']

def steamIDpulling(SteamUN,key):
    #Pulls out and returns the steam id number for use in steam queries.
    steaminfo = {'key': key,'vanityurl': SteamUN}
    a = requests.get('http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/',params=steaminfo)
    k = json.loads(a.content)
    SteamID = k['response']['steamid']
    print SteamID
    return SteamID
# steampulling(steamID)
steamID = steamIDpulling(SteamUN, key)
gamespulling(steamID,key)

测试代码:

def testGetUserIDNum(self):
    '''Test for steam.py method'''

    # Pulling from setUp
    userID = self.userID
    API_URL = self.API_URL
    APIKEY = self.APIKEY   

    # constructing the URL
    self.url = API_URL + '?' + APIKEY + '&' + userID
    with patch("requests.get") as mock_requests_get:
        mock_requests_get.return_value = """{"response": {"streamid":76561197997115778}}"""
        self.assertEqual(steamIDPulling(userID,APIKEY), 76561197997115778)

def testgamespulling(self):
    '''Test gamesPulling method'''
    # Using test account due to huge JSON from normal one. 
    steamnum = self.steamnum
    with patch("requests.get") as mock_requests_get:
        jsonList = [{"response": {"game_count": 0}}]
    self.assertEqual(gamesPulling(steamnum,APIKEY),jsonList)

我得到:

Name                                   Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
hackathon/__init__.py                      0      0   100%
hackathon/admin.py                         3      3     0%   1-5
hackathon/forms.py                         9      9     0%   1-11
hackathon/migrations/0001_initial.py       6      0   100%
hackathon/migrations/__init__.py           0      0   100%
hackathon/models.py                        6      6     0%   1-11
hackathon/scripts/__init__.py              0      0   100%
hackathon/scripts/github.py              106     96     9%   17-34, 41-64, 69-97, 102-121, 126-132, 139-165, 169-175
hackathon/scripts/linkedin.py             19     19     0%   1-24
hackathon/scripts/samplescript.py   NoSource: No source for code: '/Users/DrkSephy/Documents/django-hackathon-starter/hackathon_starter/hackathon/scripts/samplescript.py'.
hackathon/scripts/steam.py                15     15     0%   3-29
hackathon/scripts/tumblr.py               60     60     0%   1-85
hackathon/tests.py                         1      0   100%
hackathon/urls.py                          3      3     0%   1-5
hackathon/views.py                        76     76     0%   1-157
--------------------------------------------------------------------
TOTAL                                    304    287     6%
----------------------------------------------------------------------
Ran 2 tests in 0.002s

OK
Destroying test database for alias 'default'...

Tags: thekeypyselfapigetresponsedef