0

本番サーバーでDjangoアプリのSeleniumテストを実行しようとしています。

finally:句で構文エラーが発生します。

エラーがどこにあるのかわかりません。開発ではすべてのテストが正常に実行されました。

コードは次のとおりです。

 def activate_revision(self, user, revision):  
    self.title = revision.title  
    self.tagnames = revision.tagnames  

    self.body = self.rendered(revision.body)  

    self.active_revision = revision  

    # Try getting the previous revision  
    try:  
        prev_revision = NodeRevision.objects.get(node=self, revision=revision.revision-1)  

        update_activity = True  

        # Do not update the activity if only the tags are changed  
        if prev_revision.title == revision.title and prev_revision.body == revision.body \  
        and prev_revision.tagnames != revision.tagnames and not settings.UPDATE_LATEST_ACTIVITY_ON_TAG_EDIT:  
            update_activity = False  
    except NodeRevision.DoesNotExist:  
        update_activity = True  
    finally:  
        if update_activity:  
            self.update_last_activity(user)  
    self.save()  

トレースバックは次のとおりです。

$ python manage.py test forum  
Traceback (most recent call last):  
  File "/usr/lib/python2.4/logging/__init__.py", line 731, in emit  
    msg = self.format(record)  
  File "/usr/lib/python2.4/logging/__init__.py", line 617, in format  
    return fmt.format(record)  
  File "/usr/lib/python2.4/logging/__init__.py", line 408, in format  
    s = self._fmt % record.__dict__  
KeyError: 'funcName'  
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_lookup method hasn't been updated to take `connection` and `prepared` arguments.  
  new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)  
/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/fields/subclassing.py:80: DeprecationWarning: A Field class whose get_db_prep_value method hasn't been updated to take `connection` and `prepared` arguments.  
  new_class = super(SubfieldBase, cls).__new__(cls, name, bases, attrs)  
Traceback (most recent call last):  
  File "manage.py", line 13, in ?  
    execute_manager(settings)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 438, in execute_manager  
    utility.execute()  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/__init__.py", line 379, in execute  
    self.fetch_command(subcommand).run_from_argv(self.argv)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 191, in run_from_argv  
    self.execute(*args, **options.__dict__)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/base.py", line 220, in execute  
    output = self.handle(*args, **options)  
  File "/home/spirituality/lib/python2.7/South-0.7.3-py2.7.egg/south/management/commands/test.py", line 8, in handle  
    super(Command, self).handle(*args, **kwargs)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/core/management/commands/test.py", line 37, in handle  
    failures = test_runner.run_tests(test_labels)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 358, in run_tests  
    suite = self.build_suite(test_labels, extra_tests)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/test/simple.py", line 247, in build_suite  
    app = get_app(label)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 129, in get_app  
    self._populate()  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 61, in _populate  
    self.load_app(app_name, True)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/db/models/loading.py", line 78, in load_app  
    models = import_module('.models', app_name)  
  File "/home/spirituality/lib/python2.7/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module  
    __import__(name)  
  File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/__init__.py", line 2, in ?  
    from question import Question ,QuestionRevision, QuestionSubscription  
  File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/question.py", line 1, in ?  
    from base import *  
  File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/base.py", line 349, in ?  
    from node import Node, NodeRevision, NodeManager  
  File "/home/spirituality/webapps/spirituality/spirit_app/forum/models/node.py", line 383  
    finally:  
          ^  
SyntaxError: invalid syntax  
4

1 に答える 1

1

トレースバックの最初の部分は、本番環境ではPython2.4であることを示しています。上記の私のコメントによると、問題はtry..except..finallyPython2.5以降のみにあるということです。本番環境をアップグレードするか、コードを書き直してtry..except、外部にネストしtry..finallyます。

于 2012-06-28T19:38:31.920 に答える