##// END OF EJS Templates
tests: conftests needs to be in the root of package for proper test collection
super-admin -
r4987:f5111bba default
parent child Browse files
Show More
@@ -1,199 +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 if call.excinfo:
139 140 exc = call.excinfo.value
140 141 vcsserver_traceback = getattr(exc, '_vcs_server_traceback', None)
141 142
142 143 if vcsserver_traceback:
143 section = 'VCSServer remote traceback ' + report.when
144 section = f'VCSServer remote traceback {report.when}'
144 145 report.sections.append((section, vcsserver_traceback))
145 146
146 147
147 148 def pytest_collection_modifyitems(session, config, items):
148 149 # nottest marked, compare nose, used for transition from nose to pytest
149 150 remaining = [
150 151 i for i in items if getattr(i.obj, '__test__', True)]
151 152 items[:] = remaining
152 153
153 154 # NOTE(marcink): custom test ordering, db tests and vcstests are slowes and should
154 155 # be executed at the end for faster test feedback
155 156 def sorter(item):
156 157 pos = 0
157 158 key = item._nodeid
158 159 if key.startswith('rhodecode/tests/database'):
159 160 pos = 1
160 161 elif key.startswith('rhodecode/tests/vcs_operations'):
161 162 pos = 2
162 163
163 164 return pos
164 165
165 166 items.sort(key=sorter)
166 167
167 168
168 169 def get_backends_from_metafunc(metafunc):
169 170 requested_backends = set(metafunc.config.getoption('--backends'))
170 171 backend_mark = metafunc.definition.get_closest_marker('backends')
171 172 if backend_mark:
172 173 # Supported backends by this test function, created from
173 174 # pytest.mark.backends
174 175 backends = backend_mark.args
175 176 elif hasattr(metafunc.cls, 'backend_alias'):
176 177 # Support class attribute "backend_alias", this is mainly
177 178 # for legacy reasons for tests not yet using pytest.mark.backends
178 179 backends = [metafunc.cls.backend_alias]
179 180 else:
180 181 backends = metafunc.config.getoption('--backends')
181 182 return requested_backends.intersection(backends)
182 183
183 184
184 185 def pytest_generate_tests(metafunc):
185 186
186 187 # Support test generation based on --backend parameter
187 188 if 'backend_alias' in metafunc.fixturenames:
188 189 backends = get_backends_from_metafunc(metafunc)
189 190 scope = None
190 191 if not backends:
191 192 pytest.skip("Not enabled for any of selected backends")
192 193
193 194 metafunc.parametrize('backend_alias', backends, scope=scope)
194 195
195 196 backend_mark = metafunc.definition.get_closest_marker('backends')
196 197 if backend_mark:
197 198 backends = get_backends_from_metafunc(metafunc)
198 199 if not backends:
199 200 pytest.skip("Not enabled for any of selected backends")
General Comments 0
You need to be logged in to leave comments. Login now