conftest.py (2197B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 from ..fixtures import * # noqa: F403 7 8 9 def pytest_generate_tests(metafunc): 10 """Generate tests based on markers.""" 11 12 if "session" not in metafunc.fixturenames: 13 return 14 15 marks = [mark.name for mark in metafunc.function.pytestmark] 16 17 otherargs = {} 18 argvalues = [] 19 ids = [] 20 21 if "only_platforms" in marks: 22 for mark in metafunc.function.pytestmark: 23 if mark.name == "only_platforms": 24 otherargs["only_platforms"] = mark.args 25 26 if "skip_platforms" in marks: 27 for mark in metafunc.function.pytestmark: 28 if mark.name == "skip_platforms": 29 otherargs["skip_platforms"] = mark.args 30 31 if "with_private_browsing" in marks: 32 otherargs["with_private_browsing"] = True 33 if "with_strict_etp" in marks: 34 otherargs["with_strict_etp"] = True 35 if "without_storage_partitioning" in marks: 36 otherargs["without_storage_partitioning"] = True 37 if "without_tcp " in marks: 38 otherargs["without_tcp "] = True 39 40 if "with_shims" in marks: 41 argvalues.append([dict({"shims": True}, **otherargs)]) 42 ids.append("with_shims") 43 44 if "without_shims" in marks: 45 argvalues.append([dict({"shims": False}, **otherargs)]) 46 ids.append("without_shims") 47 48 metafunc.parametrize(["session"], argvalues, ids=ids, indirect=True) 49 50 51 @pytest.fixture(scope="function") # noqa: F405 52 async def test_config(request, driver): 53 params = request.node.callspec.params.get("session") 54 55 use_shims = params.get("shims") 56 if use_shims is None: 57 raise ValueError( 58 f"Missing shims marker in {request.fspath}:{request.function.__name__}" 59 ) 60 61 return { 62 "aps": not params.get("without_storage_partitioning", False), 63 "use_pbm": params.get("with_private_browsing", False), 64 "use_shims": use_shims, 65 "use_strict_etp": params.get("with_strict_etp", False), 66 "without_tcp": params.get("without_tcp", False), 67 }