2 from atf_python.atf_pytest import ATFHandler
10 global DEFAULT_HANDLER
11 if DEFAULT_HANDLER is None:
12 DEFAULT_HANDLER = ATFHandler()
13 return DEFAULT_HANDLER
16 def pytest_addoption(parser):
19 group = parser.getgroup("general", "Running and selection options")
20 group.addoption("--atf-var", dest="atf_vars", action="append", default=[])
24 dest="atf_source_dir",
25 help="Path to the test source directory",
32 help="Call cleanup procedure for a given test",
34 group = parser.getgroup("terminal reporting", "reporting", after="general")
39 help="Enable test listing/results output in atf format",
45 help="Path to the status file provided by atf runtime",
50 def pytest_configure(config):
51 if config.option.help:
54 # Register markings anyway to avoid warnings
55 config.addinivalue_line("markers", "require_user(name): user to run the test with")
56 config.addinivalue_line(
57 "markers", "require_arch(names): List[str] of support archs"
59 # config.addinivalue_line("markers", "require_config(config): List[Tuple[str,Any]] of k=v pairs")
60 config.addinivalue_line(
61 "markers", "require_diskspace(amount): str with required diskspace"
63 config.addinivalue_line(
64 "markers", "require_files(space): List[str] with file paths"
66 config.addinivalue_line(
67 "markers", "require_machine(names): List[str] of support machine types"
69 config.addinivalue_line(
70 "markers", "require_memory(amount): str with required memory"
72 config.addinivalue_line(
73 "markers", "require_progs(space): List[str] with file paths"
75 config.addinivalue_line(
76 "markers", "timeout(dur): int/float with max duration in sec"
80 PLUGIN_ENABLED = config.option.atf
81 if not PLUGIN_ENABLED:
85 if config.option.collectonly:
86 # Need to output list of tests to stdout, hence override
87 # standard reporter plugin
88 reporter = config.pluginmanager.getplugin("terminalreporter")
90 config.pluginmanager.unregister(reporter)
93 def pytest_collection_modifyitems(session, config, items):
94 """If cleanup is requested, replace collected tests with their cleanups (if any)"""
95 if PLUGIN_ENABLED and config.option.atf_cleanup:
97 handler = get_handler()
99 if handler.has_object_cleanup(obj):
100 handler.override_runtest(obj)
101 new_items.append(obj)
103 items.extend(new_items)
106 def pytest_collection_finish(session):
107 if PLUGIN_ENABLED and session.config.option.collectonly:
108 handler = get_handler()
109 handler.list_tests(session.items)
112 def pytest_runtest_logreport(report):
114 handler = get_handler()
115 handler.add_report(report)
118 def pytest_unconfigure(config):
119 if PLUGIN_ENABLED and config.option.atf_file:
120 handler = get_handler()
121 handler.write_report(config.option.atf_file)