Show More
@@ -0,0 +1,201 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2010-2020 RhodeCode GmbH | |||
|
4 | # | |||
|
5 | # This program is free software: you can redistribute it and/or modify | |||
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU Affero General Public License | |||
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | import pytest | |||
|
22 | from rhodecode.lib import ext_json | |||
|
23 | ||||
|
24 | ||||
|
25 | pytest_plugins = [ | |||
|
26 | "rhodecode.tests.fixture_mods.fixture_pyramid", | |||
|
27 | "rhodecode.tests.fixture_mods.fixture_utils", | |||
|
28 | ] | |||
|
29 | ||||
|
30 | ||||
|
31 | def pytest_configure(config): | |||
|
32 | from rhodecode.config import patches | |||
|
33 | ||||
|
34 | ||||
|
35 | def pytest_addoption(parser): | |||
|
36 | ||||
|
37 | def _parse_json(value): | |||
|
38 | return ext_json.str_json(value) if value else None | |||
|
39 | ||||
|
40 | def _split_comma(value): | |||
|
41 | return value.split(',') | |||
|
42 | ||||
|
43 | parser.addoption( | |||
|
44 | '--keep-tmp-path', action='store_true', | |||
|
45 | help="Keep the test temporary directories") | |||
|
46 | ||||
|
47 | parser.addoption( | |||
|
48 | '--backends', action='store', type=_split_comma, | |||
|
49 | default=['git', 'hg', 'svn'], | |||
|
50 | help="Select which backends to test for backend specific tests.") | |||
|
51 | parser.addoption( | |||
|
52 | '--dbs', action='store', type=_split_comma, | |||
|
53 | default=['sqlite'], | |||
|
54 | help="Select which database to test for database specific tests. " | |||
|
55 | "Possible options are sqlite,postgres,mysql") | |||
|
56 | parser.addoption( | |||
|
57 | '--appenlight', '--ae', action='store_true', | |||
|
58 | help="Track statistics in appenlight.") | |||
|
59 | parser.addoption( | |||
|
60 | '--appenlight-api-key', '--ae-key', | |||
|
61 | help="API key for Appenlight.") | |||
|
62 | parser.addoption( | |||
|
63 | '--appenlight-url', '--ae-url', | |||
|
64 | default="https://ae.rhodecode.com", | |||
|
65 | help="Appenlight service URL, defaults to https://ae.rhodecode.com") | |||
|
66 | parser.addoption( | |||
|
67 | '--sqlite-connection-string', action='store', | |||
|
68 | default='', help="Connection string for the dbs tests with SQLite") | |||
|
69 | parser.addoption( | |||
|
70 | '--postgres-connection-string', action='store', | |||
|
71 | default='', help="Connection string for the dbs tests with Postgres") | |||
|
72 | parser.addoption( | |||
|
73 | '--mysql-connection-string', action='store', | |||
|
74 | default='', help="Connection string for the dbs tests with MySQL") | |||
|
75 | parser.addoption( | |||
|
76 | '--repeat', type=int, default=100, | |||
|
77 | help="Number of repetitions in performance tests.") | |||
|
78 | ||||
|
79 | parser.addoption( | |||
|
80 | '--test-loglevel', dest='test_loglevel', | |||
|
81 | help="Set default Logging level for tests, critical(default), error, warn , info, debug") | |||
|
82 | group = parser.getgroup('pylons') | |||
|
83 | group.addoption( | |||
|
84 | '--with-pylons', dest='pyramid_config', | |||
|
85 | help="Set up a Pylons environment with the specified config file.") | |||
|
86 | group.addoption( | |||
|
87 | '--ini-config-override', action='store', type=_parse_json, | |||
|
88 | default=None, dest='pyramid_config_override', help=( | |||
|
89 | "Overrides the .ini file settings. Should be specified in JSON" | |||
|
90 | " format, e.g. '{\"section\": {\"parameter\": \"value\", ...}}'" | |||
|
91 | ) | |||
|
92 | ) | |||
|
93 | parser.addini( | |||
|
94 | 'pyramid_config', | |||
|
95 | "Set up a Pyramid environment with the specified config file.") | |||
|
96 | ||||
|
97 | vcsgroup = parser.getgroup('vcs') | |||
|
98 | vcsgroup.addoption( | |||
|
99 | '--without-vcsserver', dest='with_vcsserver', action='store_false', | |||
|
100 | help="Do not start the VCSServer in a background process.") | |||
|
101 | vcsgroup.addoption( | |||
|
102 | '--with-vcsserver-http', dest='vcsserver_config_http', | |||
|
103 | help="Start the HTTP VCSServer with the specified config file.") | |||
|
104 | vcsgroup.addoption( | |||
|
105 | '--vcsserver-protocol', dest='vcsserver_protocol', | |||
|
106 | help="Start the VCSServer with HTTP protocol support.") | |||
|
107 | vcsgroup.addoption( | |||
|
108 | '--vcsserver-config-override', action='store', type=_parse_json, | |||
|
109 | default=None, dest='vcsserver_config_override', help=( | |||
|
110 | "Overrides the .ini file settings for the VCSServer. " | |||
|
111 | "Should be specified in JSON " | |||
|
112 | "format, e.g. '{\"section\": {\"parameter\": \"value\", ...}}'" | |||
|
113 | ) | |||
|
114 | ) | |||
|
115 | vcsgroup.addoption( | |||
|
116 | '--vcsserver-port', action='store', type=int, | |||
|
117 | default=None, help=( | |||
|
118 | "Allows to set the port of the vcsserver. Useful when testing " | |||
|
119 | "against an already running server and random ports cause " | |||
|
120 | "trouble.")) | |||
|
121 | parser.addini( | |||
|
122 | 'vcsserver_config_http', | |||
|
123 | "Start the HTTP VCSServer with the specified config file.") | |||
|
124 | parser.addini( | |||
|
125 | 'vcsserver_protocol', | |||
|
126 | "Start the VCSServer with HTTP protocol support.") | |||
|
127 | ||||
|
128 | ||||
|
129 | @pytest.hookimpl(tryfirst=True, hookwrapper=True) | |||
|
130 | def pytest_runtest_makereport(item, call): | |||
|
131 | """ | |||
|
132 | Adding the remote traceback if the exception has this information. | |||
|
133 | ||||
|
134 | VCSServer attaches this information as the attribute `_vcs_server_traceback` | |||
|
135 | to the exception instance. | |||
|
136 | """ | |||
|
137 | outcome = yield | |||
|
138 | report = outcome.get_result() | |||
|
139 | ||||
|
140 | if call.excinfo: | |||
|
141 | exc = call.excinfo.value | |||
|
142 | vcsserver_traceback = getattr(exc, '_vcs_server_traceback', None) | |||
|
143 | ||||
|
144 | if vcsserver_traceback and report.outcome == 'failed': | |||
|
145 | section = f'VCSServer remote traceback {report.when}' | |||
|
146 | report.sections.append((section, vcsserver_traceback)) | |||
|
147 | ||||
|
148 | ||||
|
149 | def pytest_collection_modifyitems(session, config, items): | |||
|
150 | # nottest marked, compare nose, used for transition from nose to pytest | |||
|
151 | remaining = [ | |||
|
152 | i for i in items if getattr(i.obj, '__test__', True)] | |||
|
153 | items[:] = remaining | |||
|
154 | ||||
|
155 | # NOTE(marcink): custom test ordering, db tests and vcstests are slowes and should | |||
|
156 | # be executed at the end for faster test feedback | |||
|
157 | def sorter(item): | |||
|
158 | pos = 0 | |||
|
159 | key = item._nodeid | |||
|
160 | if key.startswith('rhodecode/tests/database'): | |||
|
161 | pos = 1 | |||
|
162 | elif key.startswith('rhodecode/tests/vcs_operations'): | |||
|
163 | pos = 2 | |||
|
164 | ||||
|
165 | return pos | |||
|
166 | ||||
|
167 | items.sort(key=sorter) | |||
|
168 | ||||
|
169 | ||||
|
170 | def get_backends_from_metafunc(metafunc): | |||
|
171 | requested_backends = set(metafunc.config.getoption('--backends')) | |||
|
172 | backend_mark = metafunc.definition.get_closest_marker('backends') | |||
|
173 | if backend_mark: | |||
|
174 | # Supported backends by this test function, created from | |||
|
175 | # pytest.mark.backends | |||
|
176 | backends = backend_mark.args | |||
|
177 | elif hasattr(metafunc.cls, 'backend_alias'): | |||
|
178 | # Support class attribute "backend_alias", this is mainly | |||
|
179 | # for legacy reasons for tests not yet using pytest.mark.backends | |||
|
180 | backends = [metafunc.cls.backend_alias] | |||
|
181 | else: | |||
|
182 | backends = metafunc.config.getoption('--backends') | |||
|
183 | return requested_backends.intersection(backends) | |||
|
184 | ||||
|
185 | ||||
|
186 | def pytest_generate_tests(metafunc): | |||
|
187 | ||||
|
188 | # Support test generation based on --backend parameter | |||
|
189 | if 'backend_alias' in metafunc.fixturenames: | |||
|
190 | backends = get_backends_from_metafunc(metafunc) | |||
|
191 | scope = None | |||
|
192 | if not backends: | |||
|
193 | pytest.skip("Not enabled for any of selected backends") | |||
|
194 | ||||
|
195 | metafunc.parametrize('backend_alias', backends, scope=scope) | |||
|
196 | ||||
|
197 | backend_mark = metafunc.definition.get_closest_marker('backends') | |||
|
198 | if backend_mark: | |||
|
199 | backends = get_backends_from_metafunc(metafunc) | |||
|
200 | if not backends: | |||
|
201 | pytest.skip("Not enabled for any of selected backends") |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now