[issue17066] Fix test discovery for test_robotparser.py

Ezio Melotti report at bugs.python.org
Sun Mar 10 21:24:20 CET 2013


Ezio Melotti added the comment:

Do you think doing something like:

class BaseRobotTest:
    def setUp(self):
        lines = io.StringIO(robots_txt).readlines()
        self.parser = urllib.robotparser.RobotFileParser()
        parser.parse(lines)

    def test_good(self):
         for url in good:
             self.assertTrue(self.parser.can_fetch(...))

    def test_bad(self):
         for url in bad:
             self.assertFalse(self.parser.can_fetch(...))

class RobotTestX(BaseRobotTest, unittest.TestCase):
    doc = "..."
    good = [...]
    bad = [...]

...

would be a better approach?

On one hand is a bit more verbose and doesn't create a separate test for each URL (I don't think that's important though), but on the other hand it gets rid of lot of magic and makes the test more understandable.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17066>
_______________________________________


More information about the Python-bugs-list mailing list