Page MenuHomePhabricator

proofreadpage_tests: TestIndexPageMappingsRedlinks fails if bs4 not installed
Closed, ResolvedPublic

Description

tests.proofreadpage_tests.TestIndexPageMappingsRedlinks fails if bs4 is not installed. It should be skipped without throwing an error, like the other tests.

$ nosetests -v tests.proofreadpage_tests
Test IndexPage methods inherited from superclass BasePage. ... SKIP: bs4 not installed
Test ProofreadPage methods inherited from superclass BasePage. ... ok
Test IndexPage from invalid Site as source. ... SKIP: bs4 not installed
Test if cache is checked and loaded properly on wikisource:de ... SKIP: bs4 not installed
Test if cache is checked and loaded properly on wikisource:en ... SKIP: bs4 not installed
Test if cache is checked and loaded properly on wikisource:fr ... SKIP: bs4 not installed
Test IndexPage page get_label_from_* functions on wikisource:de ... SKIP: bs4 not installed
Test IndexPage page get_label_from_* functions on wikisource:en ... SKIP: bs4 not installed
Test IndexPage page get_label_from_* functions on wikisource:fr ... SKIP: bs4 not installed
Test IndexPage page get_page_number functions on wikisource:de ... SKIP: bs4 not installed
Test IndexPage page get_page_number functions on wikisource:en ... SKIP: bs4 not installed
Test IndexPage page get_page_number functions on wikisource:fr ... SKIP: bs4 not installed
Test num_pages property on wikisource:de ... SKIP: bs4 not installed
Test num_pages property on wikisource:en ... SKIP: bs4 not installed
Test num_pages property on wikisource:fr ... SKIP: bs4 not installed
Test Index page generator on wikisource:de ... SKIP: bs4 not installed
Test Index page generator on wikisource:en ... SKIP: bs4 not installed
Test Index page generator on wikisource:fr ... SKIP: bs4 not installed
ERROR
Test IndexPage from invalid existing Page as source. ... SKIP: bs4 not installed
Test IndexPage from invalid Link as source. ... SKIP: bs4 not installed
Test IndexPage from Page not existing in non-Page ns as source. ... SKIP: bs4 not installed
Test IndexPage from valid Link as source. ... SKIP: bs4 not installed
Test IndexPage from valid Site as source. ... SKIP: bs4 not installed
Test site.loadrevisions() with Page.text. ... SKIP: bs4 not installed
Test site.loadrevisions() with Page.text. ... ok
Test Page.quality_level when applicable. ... ok
Test index property. ... SKIP: bs4 not installed
Test ProofreadPage from invalid Site as source. ... ok
Test ProofreadPage page decomposing/composing text. ... ok
Test ProofreadPage from invalid existing Page as source. ... ok
Test ProofreadPage from invalid Link as source. ... ok
Test ProofreadPage from invalid not existing Page as source. ... ok
Test ProofreadPage from Page not existing in non-Page ns as source. ... ok
Test conversion to json format. ... ok
Test ProofreadPage page decomposing/composing text. ... ok
Test ProofreadPage page decomposing/composing text. ... ok
Test ProofreadPage from valid Link as source. ... ok
Test ProofreadPage page parsing functions. ... ok
Test ProofreadPage from valid Site as source. ... ok

======================================================================
ERROR: test suite for <class 'tests.proofreadpage_tests.TestIndexPageMappingsRedlinks'>
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 208, in run
    self.setUp()
  File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 291, in setUp
    self.setupContext(ancestor)
  File "/usr/lib/python2.7/dist-packages/nose/suite.py", line 314, in setupContext
    try_run(context, names)
  File "/usr/lib/python2.7/dist-packages/nose/util.py", line 471, in try_run
    return func()
  File "/home/ajk/Documents/wiki/pywikibot-core/tests/proofreadpage_tests.py", line 572, in setUpClass
    cls.index = IndexPage(cls.site, cls.index_name)
  File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/proofreadpage.py", line 451, in __init__
    raise BeautifulSoup
ImportError: No module named bs4

----------------------------------------------------------------------
Ran 39 tests in 15.207s

FAILED (SKIP=24, errors=1)

Event Timeline

Change 277465 had a related patch set uploaded (by AbdealiJK):
proofreadpage_tests: Require bs4 for setUpClass

https://gerrit.wikimedia.org/r/277465

jayvdb subscribed.

From the commit message, this is an Upstream problem: https://github.com/nose-devs/nose/issues/946

If that is the problem (and it does appear to be it), then we should see problems if any of the following have a setUpClass , if the setUpClass also attempts to use the required package during the setUpClass method:

$ git grep --after-context=1 '^@require_modules'
tests/interwiki_graph_tests.py:@require_modules('pydot')
tests/interwiki_graph_tests.py-class TestWiktionaryGraph(SiteAttributeTestCase):
--
tests/oauth_tests.py:@require_modules('mwoauth')
tests/oauth_tests.py-class OAuthSiteTestCase(TestCase):
--
tests/patrolbot_tests.py:@require_modules('mwparserfromhell')
tests/patrolbot_tests.py-class TestPatrolBot(DefaultDrySiteTestCase):
--
tests/proofreadpage_tests.py:@require_modules('bs4')
tests/proofreadpage_tests.py-class TestProofreadPageIndexProperty(TestCase):
--
tests/proofreadpage_tests.py:@require_modules('bs4')
tests/proofreadpage_tests.py-class IndexPageTestCase(TestCase):
--
tests/proofreadpage_tests.py:@require_modules('bs4')
tests/proofreadpage_tests.py-class TestBasePageMethodsIndexPage(BasePageMethodsTestBase):
--
tests/weblinkchecker_tests.py:@require_modules('memento_client')
tests/weblinkchecker_tests.py-class MementoTestCase(TestCase):

Those that also have a setUpClass:

  • TestWiktionaryGraph
  • TestIndexPageMappings
  • TestIndexPageMappingsRedlinks

However it looks like only TestIndexPageMappingsRedlinks creates an IndexPage during setUpClass, so this is the only case where the setUpClass depends on the required module.

An alternative solution is to delay the ImportError until BeautifulSoup is needed, however we'd need to consult the design decisions in Gerrit for 6db08c932 , as I recall we did discuss where the ImportError should be raised .

The ImportError seems to be as delayed as possible.

Shall I add the decorator in setUpClass for the following also ?

  • TestWiktionaryGraph
  • TestIndexPageMappings
  • TestIndexPageMappingsRedlinks

Possibly, we can just use setUp instead of setUpClass in such cases too.

There is no need to add it to the other test classes yet, as they do not use the required module. They might need it in the future, but some other test class might also hit this bug in the future.

So, the ideal solution is to improve the require_modules decorator, such that when decorating a class, it adds the decorator to the setUpClass automatically (possibly only when nose is being used).

Moved this to Upstream column in the pywikibot-test board

Unlikely to be solved upstream. Do you want to try improving 'require-modules`? If not, I will do it.

I will do it :)
Although I won't be able to take it up in the next 2 days.
If this is urgent (to get the tests fixed) you could take over.

Change 277465 merged by jenkins-bot:
tests/aspects: Skip setUpClass if TestCase skipped

https://gerrit.wikimedia.org/r/277465