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