mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[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:
parent
63bef8b7ab
commit
78ad4b4e4b
34
conftest.py
34
conftest.py
@ -3,6 +3,7 @@ import configparser
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
import pytest
|
import pytest
|
||||||
@ -13,6 +14,10 @@ NGROK_CLI = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
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(
|
parser.addoption(
|
||||||
'--tunnel', action="store", type="choice", choices=['ngrok', 'localtunnel'], default='ngrok',
|
'--tunnel', action="store", type="choice", choices=['ngrok', 'localtunnel'], default='ngrok',
|
||||||
help="Which tunneling method to use to expose the local Odoo server "
|
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 "
|
"blow through the former); localtunnel has no rate-limiting but "
|
||||||
"the servers are way less reliable")
|
"the servers are way less reliable")
|
||||||
|
|
||||||
|
def pytest_report_header(config):
|
||||||
|
return 'Running against database ' + config.getoption('--db')
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def config(pytestconfig):
|
def config(pytestconfig):
|
||||||
""" Flat version of the pytest config file (pytest.ini), parses to a
|
""" Flat version of the pytest config file (pytest.ini), parses to a
|
||||||
@ -140,3 +148,29 @@ def tunnel(pytestconfig, port):
|
|||||||
p.wait(30)
|
p.wait(30)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unsupported %s tunnel method" % tunnel)
|
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)
|
||||||
|
@ -29,15 +29,6 @@ DEFAULT_CRONS = [
|
|||||||
'runbot_merge.feedback_cron',
|
'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):
|
def wait_for_hook(n=1):
|
||||||
time.sleep(10 * n)
|
time.sleep(10 * n)
|
||||||
|
|
||||||
@ -137,32 +128,6 @@ def port():
|
|||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
return s.getsockname()[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
|
@pytest.fixture
|
||||||
def server(request, db, port, module):
|
def server(request, db, port, module):
|
||||||
p = subprocess.Popen([
|
p = subprocess.Popen([
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import uuid
|
||||||
|
import pytest
|
||||||
|
|
||||||
pytest_plugins = ["local"]
|
pytest_plugins = ["local"]
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
@pytest.fixture(scope='session')
|
||||||
parser.addoption("--db", action="store", help="Odoo DB to run tests with")
|
def module():
|
||||||
parser.addoption('--addons-path', action='store', help="Odoo's addons path")
|
return 'runbot_merge'
|
||||||
|
@ -18,6 +18,10 @@ def gh():
|
|||||||
with fake_github.Github() as gh:
|
with fake_github.Github() as gh:
|
||||||
yield gh
|
yield gh
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def db(dbcache):
|
||||||
|
return dbcache
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def registry(request):
|
def registry(request):
|
||||||
""" Set up Odoo & yields a registry to the specified db
|
""" Set up Odoo & yields a registry to the specified db
|
||||||
|
@ -63,10 +63,6 @@ import requests
|
|||||||
def pytest_addhooks(pluginmanager):
|
def pytest_addhooks(pluginmanager):
|
||||||
pluginmanager.set_blocked('local')
|
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
|
PORT=8069
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
Loading…
Reference in New Issue
Block a user