ClickHouse/tests/queries/conftest.py

85 lines
2.4 KiB
Python
Raw Normal View History

2019-05-31 17:32:34 +00:00
import os
2021-06-07 17:29:19 +00:00
import re
2019-05-31 17:32:34 +00:00
import sys
2021-06-11 15:27:32 +00:00
import pytest
2019-05-31 17:32:34 +00:00
2020-10-02 16:54:07 +00:00
from .server import ServerThread
2019-05-31 17:32:34 +00:00
2021-06-07 17:29:19 +00:00
# Command-line arguments
2019-05-31 17:32:34 +00:00
def pytest_addoption(parser):
2021-06-11 15:27:32 +00:00
parser.addoption("--builddir", action="store", default=None, help="Path to build directory to use binaries from")
parser.addoption("--antlr", action="store_true", default=False, help="Use ANTLR parser")
2019-05-31 17:32:34 +00:00
2021-06-07 17:29:19 +00:00
# HTML report hooks
def pytest_html_report_title(report):
report.title = "ClickHouse Functional Stateless Tests (PyTest)"
RE_TEST_NAME = re.compile(r"\[(.*)\]")
def pytest_itemcollected(item):
match = RE_TEST_NAME.search(item.name)
if match:
item._nodeid = match.group(1)
# Fixtures
2019-05-31 17:32:34 +00:00
@pytest.fixture(scope='module')
def cmdopts(request):
return {
'builddir': request.config.getoption("--builddir"),
2021-06-11 15:27:32 +00:00
'antlr': request.config.getoption("--antlr"),
2019-05-31 17:32:34 +00:00
}
@pytest.fixture(scope='module')
def bin_prefix(cmdopts):
prefix = 'clickhouse'
if cmdopts['builddir'] is not None:
2020-04-03 13:54:11 +00:00
prefix = os.path.join(cmdopts['builddir'], 'programs', prefix)
# FIXME: does this hangs the server start for some reason?
# if not os.path.isabs(prefix):
# prefix = os.path.abspath(prefix)
2019-05-31 17:32:34 +00:00
return prefix
2021-06-11 15:27:32 +00:00
@pytest.fixture(scope='module')
def use_antlr(cmdopts):
return cmdopts['antlr']
2019-05-31 17:32:34 +00:00
# TODO: also support stateful queries.
QUERIES_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '0_stateless')
@pytest.fixture(scope='module', params=[f for f in os.listdir(QUERIES_PATH) if f.endswith('.sql')])
def sql_query(request):
return os.path.join(QUERIES_PATH, os.path.splitext(request.param)[0])
2020-11-11 15:29:36 +00:00
@pytest.fixture(scope='module', params=[f for f in os.listdir(QUERIES_PATH) if f.endswith('.sh')])
def shell_query(request):
return os.path.join(QUERIES_PATH, os.path.splitext(request.param)[0])
2019-05-31 17:32:34 +00:00
@pytest.fixture
2019-06-14 16:53:16 +00:00
def standalone_server(bin_prefix, tmp_path):
server = ServerThread(bin_prefix, str(tmp_path))
2019-05-31 17:32:34 +00:00
server.start()
wait_result = server.wait()
if wait_result is not None:
with open(os.path.join(server.log_dir, 'server', 'stdout.txt'), 'r') as f:
2020-10-02 16:54:07 +00:00
print(f.read(), file=sys.stderr)
2019-05-31 17:32:34 +00:00
with open(os.path.join(server.log_dir, 'server', 'stderr.txt'), 'r') as f:
2020-10-02 16:54:07 +00:00
print(f.read(), file=sys.stderr)
2019-05-31 17:32:34 +00:00
pytest.fail('Server died unexpectedly with code {code}'.format(code=server._proc.returncode), pytrace=False)
yield server
server.stop()