mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-18 13:14:37 +03:00
Load settings automatically for each test
This uses a fixture to load the default settings file before each test.
Tests that require a different settings file (ie test_settings) can be
configured to skip this step using this line of code:
@pytest.mark.load_default_settings(False)
This change is necessary to be able to run these tests in isolation from
each other. The `altlink`, `getUrl` and `downloadBinaryFile` functions
are all dependent on Settings, and you cannot test them without loading
a Settings file first. Without this change, when these tests ran, they
used a Settings object loaded up in some previous test, which could have
loaded some Settings file that we do not want. If we try to run these
tests without loading a Settings file, they will just fail to run
because Settings doesn't exist yet.
This commit is contained in:
@@ -14,6 +14,13 @@ from aqt.helper import Settings, get_hash, getUrl, retry_on_errors
|
||||
from aqt.metadata import Version
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def load_default_settings(use_defaults: bool = True):
|
||||
"""For each test, first load the default settings file, unless marked otherwise"""
|
||||
if use_defaults:
|
||||
helper.Settings.load_settings()
|
||||
|
||||
|
||||
def test_helper_altlink(monkeypatch):
|
||||
class Message:
|
||||
headers = {"content-type": "text/plain", "length": 300}
|
||||
@@ -56,6 +63,7 @@ def test_helper_altlink(monkeypatch):
|
||||
assert newurl.startswith("http://ftp.jaist.ac.jp/")
|
||||
|
||||
|
||||
@pytest.mark.load_default_settings(False)
|
||||
def test_settings(tmp_path):
|
||||
helper.Settings.load_settings(os.path.join(os.path.dirname(__file__), "data", "settings.ini"))
|
||||
assert helper.Settings.concurrency == 3
|
||||
|
||||
Reference in New Issue
Block a user