Skip to content

Commit

Permalink
Merge pull request #31 from guewen/fix-flapping-build
Browse files Browse the repository at this point in the history
Fix flapping tests
  • Loading branch information
guewen authored Nov 22, 2017
2 parents bc01f5e + 7f0b051 commit 3dc8e39
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 82 deletions.
38 changes: 26 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
language: python
python: 2.7
python:
- 2.7
- 3.6

env:
globals:
- SOURCE_CONFIG_FILE=${TRAVIS_BUILD_DIR}/tests/config/odoo-travis.cfg
- ODOOVERSION=9.0 LINT=false
- ODOOVERSION=10.0 LINT=false

matrix:
exclude:
- python: 3.6
env: ODOOVERSION=9.0 LINT=false
- python: 3.6
env: ODOOVERSION=10.0 LINT=false
include:
- python: 3.6
env: LINT=true

services:
- postgresql

virtualenv:
# needed for lxml, lxml installed with pip in the virtualenv gives an
# error on travis
system_site_packages: true

addons:
postgresql: "9.4"
postgresql: "9.6"
apt:
packages:
- python-lxml # because pip installation is slow

install:
- pip install flake8 invoke tox
before_script:
- if [ "$LINT" == false ] ; then virtualenv /tmp/venv-${ODOOVERSION} ; fi
- if [ "$LINT" == false ] ; then source /tmp/venv-${ODOOVERSION}/bin/activate ; fi
- if [ "$LINT" == false ] ; then pip install invoke pytest ; fi
- if [ "$LINT" == false ] ; then pip install . ; fi
- if [ "$LINT" == false ] ; then invoke tests.prepare-version "${ODOOVERSION}" ; fi
- if [ "$LINT" == true ] ; then pip install flake8 readme_renderer ; fi

script:
- tox
- if [ "$LINT" == false ] ; then OPENERP_SERVER=/tmp/test-anthem-config-${ODOOVERSION}.cfg py.test tests ; fi
- if [ "$LINT" == true ] ; then flake8 anthem tests ; fi
- if [ "$LINT" == true ] ; then python setup.py check -r -s ; fi
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Unreleased


0.10.0 (2017-09-19)
------------------
-------------------

**Bugfixes**

Expand Down
38 changes: 22 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,39 @@ Run the tests
~~~~~~~~~~~~~

To run ``anthem``'s tests, it is a good idea to do an *editable* install of it
in a virtualenv, and then intall and run ``tox`` as follows::
in a virtualenv. You must also prepare the environment by installing odoo packages.

Odoo 9.0 (Python 2)::

$ git clone https://github.com/camptocamp/anthem.git
Cloning into 'anthem'...
$ cd anthem
$ python2 -m virtualenv env
$ source env/bin/activate
$ virtualenv -p python2 env-9.0
$ source env-9.0/bin/activate
$ pip install -e .
$ pip install pytest invoke tox
$ tox

Additional arguments will be passed to ``pytest``::
$ invoke tests.prepare-version 9.0
$ OPENERP_SERVER=/tmp/test-anthem-config-9.0.cfg py.test -s tests

$ tox -e py27 -- -x tests/test_cli.py
Odoo 10.0 (Python 2)::

If you prefer to execute the tests directly with ``pytest``, you can run::

$ OPENERP_SERVER=tests/config/odoo.cfg py.test
$ git clone https://github.com/camptocamp/anthem.git
Cloning into 'anthem'...
$ cd anthem
$ virtualenv -p python2 env-10.0
$ source env-10.0/bin/activate
$ pip install -e .
$ pip install pytest invoke tox
$ invoke tests.prepare-version 10.0
$ OPENERP_SERVER=/tmp/test-anthem-config-10.0.cfg py.test -s tests

But before, you have to ensure to have the proper environment for the tests with::
If need be, you can drop the test database with (adapt the version)::

$ invoke tests.prepare
$ invoke tests.createdb
$ invoke tests.dropdb 9.0

Those steps, automatically called when using ``tox``, will download the nightly
release of Odoo and install it as a package, so tests can be run against it
(and that's also why it is important to use a virtualenv!)
These steps will download the nightly release of Odoo install it as a package
then install a database, so tests can be run against it (and that's also why it
is important to use a virtualenv!)

When calling ``pytest``, you have to define the ``OPENERP_SERVER`` environment
variable with the configuration file for the Odoo database that will be used
Expand Down
2 changes: 2 additions & 0 deletions anthem/lyrics/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import codecs
import csv

from past.types import basestring

from ..exceptions import AnthemError


Expand Down
2 changes: 1 addition & 1 deletion anthem/lyrics/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def uninstall(ctx, module_list):
mods = ctx.env['ir.module.module'].search([('name', 'in', module_list)])
try:
mods.button_immediate_uninstall()
except:
except Exception:
raise AnthemError(u'Cannot uninstall modules. See the logs')


Expand Down
1 change: 1 addition & 0 deletions anthem/lyrics/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2016 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html)

from past.types import basestring
from contextlib import contextmanager


Expand Down
1 change: 1 addition & 0 deletions anthem/lyrics/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html)
from past.types import basestring


def define_settings(ctx, model, values):
Expand Down
2 changes: 1 addition & 1 deletion anthem/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def display(self, name, timing=True):
start = time.time()
try:
yield
except:
except Exception:
self.level -= 1
self.print_indent(u'{}: error'.format(name))
raise
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup, find_packages

with open('anthem/__init__.py') as f:
version = re.search('^__version__\s*=\s*"(.*)"', f.read(), re.M).group(1)
version = re.search(r'^__version__\s*=\s*"(.*)"', f.read(), re.M).group(1)
with open('README.rst') as f:
readme = f.read()
with open('HISTORY.rst') as f:
Expand All @@ -24,6 +24,7 @@
entry_points={
'console_scripts': ['anthem = anthem.cli:main']
},
install_requires=['future'],
classifiers=(
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
Expand Down
11 changes: 7 additions & 4 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ def tests_prepare_config(ctx, version, source, target):


@task(default=True)
def tests_run(ctx):
ctx.run('tox', pty=True)
def tests_prepare_version(ctx, version):
tests_prepare(ctx, version)
config_file = '/tmp/test-anthem-config-%s.cfg' % version
tests_prepare_config(ctx, version, 'tests/config/odoo.cfg', config_file)
tests_createdb(ctx, version)


tests.add_task(tests_run, 'run')
tests.add_task(tests_prepare_version, 'prepare-version')
tests.add_task(tests_createdb, 'createdb')
tests.add_task(tests_dropdb, 'dropdb')
tests.add_task(tests_prepare, 'prepare')
tests.add_task(tests_prepare_config, 'prepare_config')
tests.add_task(tests_prepare_config, 'prepare-config')
2 changes: 1 addition & 1 deletion tests/test_lyrics_uninstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
import anthem.cli
from anthem.lyrics.uninstaller import uninstall
from anthem.lyrics.modules import uninstall
from anthem.exceptions import AnthemError


Expand Down
45 changes: 0 additions & 45 deletions tox.ini

This file was deleted.

0 comments on commit 3dc8e39

Please sign in to comment.