diff --git a/doc/test-framework.rst b/doc/test-framework.rst index 56951b1a8e1..17a7b480640 100644 --- a/doc/test-framework.rst +++ b/doc/test-framework.rst @@ -87,9 +87,9 @@ In addition to the above possibilities, when invoked with a non-existing module sub-modules. Depending on the unittest2_ class that is used to write the tests (see -``openerp.tests.common`` for some helper classes that you can re-use), a database -may be created before the test is run, and the module providing the test will -be installed on that database. +:mod:`openerp.tests.common` for some helper classes that you can re-use), a +database may be created before the test is run, and the module providing the +test will be installed on that database. Because creating a database, installing modules, and then dropping it is expensive, it is possible to interleave the run of the ``fast_suite`` tests @@ -98,3 +98,20 @@ each requested module is installed, its fast_suite tests are run. The database is thus created and dropped (and the modules installed) only once. .. _unittest2: http://pypi.python.org/pypi/unittest2 + +TestCase subclasses +------------------- + +.. automodule:: openerp.tests.common + :members: + +.. note:: + + The `setUp` and `tearDown` methods are not part of the tests. Uncaught + exceptions in those methods are errors, not test failures. In particular, + a failing `setUp` will not be followed by a `tearDown` causing any + allocated resource in the `setUp` to not be released by the `tearDown`. + + In the :py:class:`openerp.tests.common.TransactionCase` and + :py:class:`openerp.tests.common.SingleTransactionCase`, this means the + test suite can hang because of unclosed cursors. diff --git a/openerp-server b/openerp-server index 9025e2d50c2..5501eba2159 100755 --- a/openerp-server +++ b/openerp-server @@ -101,6 +101,7 @@ def preload_registry(dbname): def run_test_file(dbname, test_file): """ Preload a registry, possibly run a test file, and start the cron.""" try: + config = openerp.tools.config db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False) cr = db.cursor() _logger.info('loading test file %s', test_file) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 4c3330c97b7..10ec38e4877 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -1548,7 +1548,6 @@ class BaseModel(object): ) self._invalids.update(fields) if error_msgs: - cr.rollback() raise except_orm('ValidateError', '\n'.join(error_msgs)) else: self._invalids.clear() diff --git a/openerp/tests/common.py b/openerp/tests/common.py index f05be10f098..3cc8b126c02 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -1,4 +1,8 @@ # -*- coding: utf-8 -*- +""" +The module :mod:`openerp.tests.common` provides a few helpers and classes to write +tests. +""" import threading import time import unittest2 @@ -115,8 +119,8 @@ class RpcCase(unittest2.TestCase): Subclass of TestCase with a few XML-RPC proxies. """ - def __init__(self, name): - super(RpcCase, self).__init__(name) + def __init__(self, methodName='runTest'): + super(RpcCase, self).__init__(methodName) class A(object): pass diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index 501ab30d879..5defce5b655 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -286,8 +286,11 @@ class YamlInterpreter(object): model = self.get_model(record.model) view_id = record.view - if view_id and (view_id is not True): - view_id = self.pool.get('ir.model.data').get_object_reference(self.cr, SUPERUSER_ID, self.module, record.view)[1] + if view_id and (view_id is not True) and isinstance(view_id, basestring): + module = self.module + if '.' in view_id: + module, view_id = view_id.split('.',1) + view_id = self.pool.get('ir.model.data').get_object_reference(self.cr, SUPERUSER_ID, module, view_id)[1] if model.is_transient(): record_dict=self.create_osv_memory_record(record, fields) diff --git a/openerp/tools/yaml_tag.py b/openerp/tools/yaml_tag.py index aca802c374a..b22787ddf98 100644 --- a/openerp/tools/yaml_tag.py +++ b/openerp/tools/yaml_tag.py @@ -109,6 +109,8 @@ def assert_constructor(loader, node): def record_constructor(loader, node): kwargs = loader.construct_mapping(node) + assert "model" in kwargs, "'model' argument is required for !record" + assert "id" in kwargs, "'id' argument is required for !record" return Record(**kwargs) def python_constructor(loader, node):