[IMP] runbot_merge, forwardport: consolidate conftests

Converge the pytest setups of runbot_merge and forwardport a bit
more (the goal is obviously to eventually share the infrastructure so
they run the same way).
This commit is contained in:
Xavier Morel 2019-09-23 13:54:42 +02:00
parent 63bef8b7ab
commit 78ad4b4e4b
5 changed files with 44 additions and 42 deletions

View File

@ -3,6 +3,7 @@ import configparser
import re
import subprocess
import time
import uuid
import psutil
import pytest
@ -13,6 +14,10 @@ NGROK_CLI = [
]
def pytest_addoption(parser):
parser.addoption('--addons-path')
parser.addoption('--db', help="DB to run the tests against", default=str(uuid.uuid4()))
parser.addoption("--no-delete", action="store_true", help="Don't delete repo after a failed run")
parser.addoption(
'--tunnel', action="store", type="choice", choices=['ngrok', 'localtunnel'], default='ngrok',
help="Which tunneling method to use to expose the local Odoo server "
@ -23,6 +28,9 @@ def pytest_addoption(parser):
"blow through the former); localtunnel has no rate-limiting but "
"the servers are way less reliable")
def pytest_report_header(config):
return 'Running against database ' + config.getoption('--db')
@pytest.fixture(scope="session")
def config(pytestconfig):
""" Flat version of the pytest config file (pytest.ini), parses to a
@ -140,3 +148,29 @@ def tunnel(pytestconfig, port):
p.wait(30)
else:
raise ValueError("Unsupported %s tunnel method" % tunnel)
@pytest.fixture(scope='session')
def dbcache(request, module):
""" Creates template DB once per run, then just duplicates it before
starting odoo and running the testcase
"""
db = request.config.getoption('--db')
subprocess.run([
'odoo', '--no-http',
'--addons-path', request.config.getoption('--addons-path'),
'-d', db, '-i', module,
'--max-cron-threads', '0',
'--stop-after-init'
], check=True)
yield db
subprocess.run(['dropdb', db])
@pytest.fixture
def db(request, dbcache):
rundb = str(uuid.uuid4())
subprocess.run(['createdb', '-T', dbcache, rundb], check=True)
yield rundb
if not request.config.getoption('--no-delete'):
subprocess.run(['dropdb', rundb], check=True)

View File

@ -29,15 +29,6 @@ DEFAULT_CRONS = [
'runbot_merge.feedback_cron',
]
def pytest_report_header(config):
return 'Running against database ' + config.getoption('--db')
def pytest_addoption(parser):
parser.addoption('--db', help="DB to run the tests against", default=str(uuid.uuid4()))
parser.addoption('--addons-path')
parser.addoption("--no-delete", action="store_true", help="Don't delete repo after a failed run")
def wait_for_hook(n=1):
time.sleep(10 * n)
@ -137,32 +128,6 @@ def port():
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]
@pytest.fixture(scope='session')
def dbcache(request, module):
""" Creates template DB once per run, then just duplicates it before
starting odoo and running the testcase
"""
db = request.config.getoption('--db')
subprocess.run([
'odoo', '--no-http',
'--addons-path', request.config.getoption('--addons-path'),
'-d', db, '-i', module,
'--max-cron-threads', '0',
'--stop-after-init'
], check=True)
yield db
subprocess.run(['dropdb', db])
@pytest.fixture
def db(request, dbcache):
rundb = str(uuid.uuid4())
subprocess.run(['createdb', '-T', dbcache, rundb], check=True)
yield rundb
if not request.config.getoption('--no-delete'):
subprocess.run(['dropdb', rundb], check=True)
@pytest.fixture
def server(request, db, port, module):
p = subprocess.Popen([

View File

@ -1,5 +1,8 @@
import uuid
import pytest
pytest_plugins = ["local"]
def pytest_addoption(parser):
parser.addoption("--db", action="store", help="Odoo DB to run tests with")
parser.addoption('--addons-path', action='store', help="Odoo's addons path")
@pytest.fixture(scope='session')
def module():
return 'runbot_merge'

View File

@ -18,6 +18,10 @@ def gh():
with fake_github.Github() as gh:
yield gh
@pytest.fixture
def db(dbcache):
return dbcache
@pytest.fixture(scope='session')
def registry(request):
""" Set up Odoo & yields a registry to the specified db

View File

@ -63,10 +63,6 @@ import requests
def pytest_addhooks(pluginmanager):
pluginmanager.set_blocked('local')
def pytest_addoption(parser):
parser.addoption("--no-delete", action="store_true", help="Don't delete repo after a failed run")
PORT=8069
@pytest.fixture(scope='session')