1#--------------------------------------------------------------------------
2#
3# Copyright (c) Microsoft Corporation. All rights reserved.
4#
5# The MIT License (MIT)
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the ""Software""), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25#--------------------------------------------------------------------------
26import json
27import os.path
28import sys
29
30import pytest
31
32CWD = os.path.dirname(__file__)
33
34# Ignore collection of async tests for Python 2
35collect_ignore = []
36if sys.version_info < (3, 5):
37    collect_ignore.append("asynctests")
38
39
40def pytest_addoption(parser):
41    parser.addoption("--runslow", action="store_true",
42                     default=False, help="run slow tests")
43
44def pytest_collection_modifyitems(config, items):
45    if config.getoption("--runslow"):
46        # --runslow given in cli: do not skip slow tests
47        return
48    skip_slow = pytest.mark.skip(reason="need --runslow option to run")
49    for item in items:
50        if "slow" in item.keywords:
51            item.add_marker(skip_slow)
52
53
54@pytest.fixture
55def user_password():
56    filepath = os.path.join(CWD, "credentials.json")
57    if os.path.exists(filepath):
58        with open(filepath, "r") as fd:
59            userpass = json.load(fd)["userpass"]
60            return userpass["user"], userpass["password"]
61    raise ValueError("Create a {} file with a 'userpass' key and two keys 'user' and 'password'".format(
62        filepath
63    ))
64