parameters: (dbnames)
return_statement: return rc
docstring: Preload a registries, possibly run a test file.
docstring_summary: Preload a registries, possibly run a test file.
docstring_tokens: Preload a registries possibly run a test file .
function: def preload_registries(dbnames):
      """ Preload a registries, possibly run a test file."""
      # TODO: move all config checks to args dont check tools.config here
      dbnames = dbnames or []
      rc = 0
      for dbname in dbnames:
          try:
              update_module = config['init'] or config['update']
              registry = Registry.new(dbname, update_module=update_module)
  
              # run test_file if provided
              if config['test_file']:
                  test_file = config['test_file']
                  if not os.path.isfile(test_file):
                      _logger.warning('test file %s cannot be found', test_file)
                  elif not test_file.endswith('py'):
                      _logger.warning('test file %s is not a python file', test_file)
                  else:
                      _logger.info('loading test file %s', test_file)
                      load_test_file_py(registry, test_file)
  
              # run post-install tests
              if config['test_enable']:
                  t0 = time.time()
                  t0_sql = odoo.sql_db.sql_counter
                  module_names = (registry.updated_modules if update_module else
                                  sorted(registry._init_modules))
                  _logger.info("Starting post tests")
                  tests_before = registry._assertion_report.testsRun
                  result = loader.run_suite(loader.make_suite(module_names, 'post_install'))
                  registry._assertion_report.update(result)
                  _logger.info("%d post-tests in %.2fs, %s queries",
                               registry._assertion_report.testsRun - tests_before,
                               time.time() - t0,
                               odoo.sql_db.sql_counter - t0_sql)
  
              if not registry._assertion_report.wasSuccessful():
                  rc += 1
          except Exception:
              _logger.critical('Failed to initialize database `%s`.', dbname, exc_info=True)
              return -1
      return rc
function_tokens: def preload_registries ( dbnames ) : # TODO: move all config checks to args dont check tools.config here dbnames = dbnames or [ ] rc = 0 for dbname in dbnames : try : update_module = config [ 'init' ] or config [ 'update' ] registry = Registry . new ( dbname , update_module = update_module ) # run test_file if provided if config [ 'test_file' ] : test_file = config [ 'test_file' ] if not os . path . isfile ( test_file ) : _logger . warning ( 'test file %s cannot be found' , test_file ) elif not test_file . endswith ( 'py' ) : _logger . warning ( 'test file %s is not a python file' , test_file ) else : _logger . info ( 'loading test file %s' , test_file ) load_test_file_py ( registry , test_file ) # run post-install tests if config [ 'test_enable' ] : t0 = time . time ( ) t0_sql = odoo . sql_db . sql_counter module_names = ( registry . updated_modules if update_module else sorted ( registry . _init_modules ) ) _logger . info ( "Starting post tests" ) tests_before = registry . _assertion_report . testsRun result = loader . run_suite ( loader . make_suite ( module_names , 'post_install' ) ) registry . _assertion_report . update ( result ) _logger . info ( "%d post-tests in %.2fs, %s queries" , registry . _assertion_report . testsRun - tests_before , time . time ( ) - t0 , odoo . sql_db . sql_counter - t0_sql ) if not registry . _assertion_report . wasSuccessful ( ) : rc += 1 except Exception : _logger . critical ( 'Failed to initialize database `%s`.' , dbname , exc_info = True ) return - 1 return rc