nosetest失败,但外部使用代码通过

时间:2013-12-22 17:50:15

标签: python debugging travis-ci nosetests

这个问题几周来一直困扰着我。我正在研究这个Hacker News API工作得很好。所有测试都在本地传递:

(HackerNewsAPI)karan:HackerNewsAPI$ nosetests -v 
Checks if the pagination works for the front page. ... ok
Checks if the pagination works for the newest page. ... ok
Checks if the pagination works for the best page. ... ok
Checks if the dict returned by scraping the best page of HN is 30. ... ok
Checks if the dict returned by scraping the front page of HN is 30. ... ok
Checks if the dict returned by scraping the newest page of HN is 30. ... ok
Checks data type of each field of each story from best page ... ok
Checks data type of each field of each story from newest page ... ok
Checks data type of each field of each story from front page. ... ok

----------------------------------------------------------------------
Ran 9 tests in 16.695s

OK

然而,在Travis上,一次测试失败了 - https://travis-ci.org/karan/HackerNewsAPI/jobs/15799138#L361

======================================================================
FAIL: Checks if the pagination works for the best page.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.7/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/travis/build/karan/HackerNewsAPI/tests/test_pagination.py", line 25, in test_pagination_best_for_2_pages
    assert len(stories) == 2 * 30
AssertionError: 
-------------------- >> begin captured logging << --------------------
requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): news.ycombinator.com
requests.packages.urllib3.connectionpool: DEBUG: "GET /best HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): news.ycombinator.com
requests.packages.urllib3.connectionpool: DEBUG: "GET /x?fnid=rCw2Votbz10Qkphm6oqLL8 HTTP/1.1" 200 None
--------------------- >> end captured logging << ---------------------

我尽我所能,到处寻找,但无法找到解决方案。它在py2和py3都失败了。只是这个特定的测试,而不是任何其他。它在本地系统上不会失败。

这里有什么问题?

主要代码文件:https://github.com/karan/HackerNewsAPI/blob/master/hn/hn.py .travis.yml档案:https://github.com/karan/HackerNewsAPI/blob/master/.travis.yml

Addemdum

在过去一小时左右,具体测试也在本地失败。所以我开始调试它。问题是,在测试中test_pagination_best_for_2_pagesstories = hn.get_stories(story_type='best', page_limit=2)应该会产生len(stories) == 60(每页30个故事)。但由于某种原因,它只获得第一页(因此,30个故事)。

但是,如果我写一个简短的程序:

from hn import HN

hn = HN()
print len(hn.get_stories(story_type='best', page_limit=2))

这会打印60。这是怎么回事?

0 个答案:

没有答案