Search code examples
pythondjangolxmlnoselettuce

Getting started with lettuce: "XMLSyntaxError: None"


I've been trying to get a basic set of Lettuce tests up and running in a django project, but I've run into a few problems.

I followed the example tutorial on the lettuce website, but I keep getting the following error when I run python manage.py harvest:

Feature: Rocking with lettuce and django               #apps/my_app/features/index.feature:1

  Scenario: Simple Hello World                         # apps/my_app/features/index.feature:3
    Given I access the url "/admin"                    # apps/my_app/features/index-steps.py:12
    Given I access the url "/admin"                    # apps/my_app/features/index-steps.py:12
    Traceback (most recent call last):
      File "/home/myhome/.virtualenvs/my_env/lib/python2.7/site-packages/lettuce/core.py", line 141, in __call__
        ret = self.function(self.step, *args, **kw)
      File "/home/myhome/code/my_app/apps/my_app/features/index-steps.py", line 14, in access_url
        world.dom = html.fromstring(response.content)
      File "/home/myhome/.virtualenvs/my_env/lib/python2.7/site-packages/lxml/html/__init__.py", line 634, in fromstring
        doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
      File "/home/myhome/.virtualenvs/my_env/lib/python2.7/site-packages/lxml/html/__init__.py", line 532, in document_fromstring
        value = etree.fromstring(html, parser, **kw)
      File "lxml.etree.pyx", line 2756, in lxml.etree.fromstring (src/lxml/lxml.etree.c:54726)
      File "parser.pxi", line 1578, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82843)
      File "parser.pxi", line 1457, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:81641)
      File "parser.pxi", line 965, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:78311)
      File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74567)
      File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75458)
      File "parser.pxi", line 601, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74958)
    XMLSyntaxError: None
    Then I see the header "Log in | Django site admin" # apps/my_app/features/index-steps.py:17
    Then I see the header "Log in | Django site admin" # apps/my_app/features/index-steps.py:17

1 feature (0 passed)
1 scenario (0 passed)
2 steps (1 failed, 1 skipped, 0 passed)

I have the following installed in my virtual environment:

Django==1.4.1
MySQL-python==1.2.3
South==0.7.6
Werkzeug==0.8.3
boto==2.6.0
cssselect==0.7.1
django-extensions==0.9
django-nose==1.1
django-storages==1.1.5
django-tastypie==0.9.11
fuzzywuzzy==0.1
lettuce==0.2.10
lxml==2.3.5
mimeparse==0.1.3
mock==1.0.0
nose==1.2.1
python-dateutil==1.5
selenium==2.25.0
sure==1.0.6
wsgiref==0.1.2

Is this a bug, or have I made some mistake somewhere? I would have thought the example would have covered it...


Solution

  • Apparently, the error was a red herring. I was getting XMLSyntaxError because the response from the URL was empty (the URL I was checking was missing a trailing slash, in this case).

    So, should anyone come across this problem, always verify that your own code works before blaming someone else's.