mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
Add openpype_mongo command flag for testing. (#5676)
* Add openpype_mongo command flag for testing. * Revert back to TEST_OPENPYPE_MONGO TEST_OPENPYPE_MONGO is placeholder used in all source test sip in `input/env_vars/env_var` not a env variable itself * Fix openpype_mongo fixture Fixture decorator was missing. If value passed from command line should be used, it must come first as `env_var` fixture should already contain valid default Mongo uri. * Renamed command line argument to mongo_url --------- Co-authored-by: kalisp <petr.kalis@gmail.com>
This commit is contained in:
parent
17dbe5b718
commit
e78b6065ac
4 changed files with 33 additions and 5 deletions
|
|
@ -290,11 +290,15 @@ def run(script):
|
|||
"--setup_only",
|
||||
help="Only create dbs, do not run tests",
|
||||
default=None)
|
||||
@click.option("--mongo_url",
|
||||
help="MongoDB for testing.",
|
||||
default=None)
|
||||
def runtests(folder, mark, pyargs, test_data_folder, persist, app_variant,
|
||||
timeout, setup_only):
|
||||
timeout, setup_only, mongo_url):
|
||||
"""Run all automatic tests after proper initialization via start.py"""
|
||||
PypeCommands().run_tests(folder, mark, pyargs, test_data_folder,
|
||||
persist, app_variant, timeout, setup_only)
|
||||
persist, app_variant, timeout, setup_only,
|
||||
mongo_url)
|
||||
|
||||
|
||||
@main.command(help="DEPRECATED - run sync server")
|
||||
|
|
|
|||
|
|
@ -213,7 +213,8 @@ class PypeCommands:
|
|||
pass
|
||||
|
||||
def run_tests(self, folder, mark, pyargs,
|
||||
test_data_folder, persist, app_variant, timeout, setup_only):
|
||||
test_data_folder, persist, app_variant, timeout, setup_only,
|
||||
mongo_url):
|
||||
"""
|
||||
Runs tests from 'folder'
|
||||
|
||||
|
|
@ -226,6 +227,10 @@ class PypeCommands:
|
|||
end
|
||||
app_variant (str): variant (eg 2020 for AE), empty if use
|
||||
latest installed version
|
||||
timeout (int): explicit timeout for single test
|
||||
setup_only (bool): if only preparation steps should be
|
||||
triggered, no tests (useful for debugging/development)
|
||||
mongo_url (str): url to Openpype Mongo database
|
||||
"""
|
||||
print("run_tests")
|
||||
if folder:
|
||||
|
|
@ -264,6 +269,15 @@ class PypeCommands:
|
|||
if setup_only:
|
||||
args.extend(["--setup_only", setup_only])
|
||||
|
||||
if mongo_url:
|
||||
args.extend(["--mongo_url", mongo_url])
|
||||
else:
|
||||
msg = (
|
||||
"Either provide uri to MongoDB through environment variable"
|
||||
" OPENPYPE_MONGO or the command flag --mongo_url"
|
||||
)
|
||||
assert not os.environ.get("OPENPYPE_MONGO"), msg
|
||||
|
||||
print("run_tests args: {}".format(args))
|
||||
import pytest
|
||||
pytest.main(args)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ def pytest_addoption(parser):
|
|||
help="True - only setup test, do not run any tests"
|
||||
)
|
||||
|
||||
parser.addoption(
|
||||
"--mongo_url", action="store", default=None,
|
||||
help="Provide url of the Mongo database."
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_data_folder(request):
|
||||
|
|
@ -55,6 +60,11 @@ def setup_only(request):
|
|||
return request.config.getoption("--setup_only")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def mongo_url(request):
|
||||
return request.config.getoption("--mongo_url")
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
# execute all other hooks to obtain the report object
|
||||
|
|
|
|||
|
|
@ -147,11 +147,11 @@ class ModuleUnitTest(BaseTest):
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def db_setup(self, download_test_data, env_var, monkeypatch_session,
|
||||
request):
|
||||
request, mongo_url):
|
||||
"""Restore prepared MongoDB dumps into selected DB."""
|
||||
backup_dir = os.path.join(download_test_data, "input", "dumps")
|
||||
|
||||
uri = os.environ.get("OPENPYPE_MONGO")
|
||||
uri = mongo_url or os.environ.get("OPENPYPE_MONGO")
|
||||
db_handler = DBHandler(uri)
|
||||
db_handler.setup_from_dump(self.TEST_DB_NAME, backup_dir,
|
||||
overwrite=True,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue