Skip to content

Commit 44cc10b

Browse files
committed
Make wpt's test_install always install into tmp dirs
This avoids mutating the venv state when running tests, which leads to order-dependent behaviour of tests.
1 parent dbb289b commit 44cc10b

File tree

1 file changed

+26
-48
lines changed

1 file changed

+26
-48
lines changed

tools/wpt/tests/test_install.py

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,34 @@
77

88
import pytest
99

10-
from tools.wpt import browser, utils, wpt
10+
from tools.wpt import browser, wpt
1111

1212

1313
@pytest.mark.slow
1414
@pytest.mark.remote_network
15-
def test_install_chromium():
16-
venv_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir())
15+
def test_install_chromium(tmp_path):
1716
channel = "nightly"
18-
dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", channel)
1917
if sys.platform == "win32":
20-
chromium_path = os.path.join(dest, "chrome-win")
18+
chromium_dir = "chrome-win"
2119
elif sys.platform == "darwin":
22-
chromium_path = os.path.join(dest, "chrome-mac")
20+
chromium_dir = "chrome-mac"
2321
else:
24-
chromium_path = os.path.join(dest, "chrome-linux")
22+
chromium_dir = "chrome-linux"
2523

26-
if os.path.exists(chromium_path):
27-
utils.rmtree(chromium_path)
2824
with pytest.raises(SystemExit) as excinfo:
29-
wpt.main(argv=["install", "chromium", "browser"])
25+
wpt.main(argv=["install", "-d", str(tmp_path), "chromium", "browser"])
3026
assert excinfo.value.code == 0
31-
assert os.path.exists(chromium_path)
27+
assert os.path.isdir(os.path.join(tmp_path, "browsers", channel, chromium_dir))
3228

3329
chromium = browser.Chromium(logging.getLogger("Chromium"))
34-
binary = chromium.find_binary(venv_path, channel)
30+
binary = chromium.find_binary(str(tmp_path), channel)
3531
assert binary is not None and os.path.exists(binary)
3632

37-
utils.rmtree(chromium_path)
38-
3933

4034
@pytest.mark.slow
4135
@pytest.mark.remote_network
42-
def test_install_chrome():
43-
venv_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir())
36+
def test_install_chrome(tmp_path):
4437
channel = "dev"
45-
dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", channel)
46-
4738
uname = platform.uname()
4839
chrome_platform = {
4940
"Linux": "linux",
@@ -58,59 +49,46 @@ def test_install_chrome():
5849
else:
5950
bits = ""
6051

61-
chrome_path = os.path.join(dest, f"chrome-{chrome_platform}{bits}")
52+
chrome_dir = f"chrome-{chrome_platform}{bits}"
6253

63-
if os.path.exists(chrome_path):
64-
utils.rmtree(chrome_path)
6554
with pytest.raises(SystemExit) as excinfo:
66-
wpt.main(argv=["install", "--channel", channel, "chrome", "browser"])
55+
wpt.main(argv=["install", "-d", str(tmp_path), "--channel", channel, "chrome", "browser"])
6756
assert excinfo.value.code == 0
68-
assert os.path.exists(chrome_path)
57+
assert os.path.isdir(os.path.join(tmp_path, "browsers", channel, chrome_dir))
6958

7059
chrome = browser.Chrome(logging.getLogger("Chrome"))
71-
binary = chrome.find_binary(venv_path, channel)
60+
binary = chrome.find_binary(tmp_path, channel)
7261
assert binary is not None and os.path.exists(binary)
7362

74-
utils.rmtree(chrome_path)
75-
7663

7764
@pytest.mark.slow
7865
@pytest.mark.remote_network
79-
def test_install_chrome_chromedriver_by_version():
66+
def test_install_chrome_chromedriver_by_version(tmp_path):
8067
# This is not technically an integration test as we do not want to require Chrome Stable to run it.
8168
chrome = browser.Chrome(logging.getLogger("Chrome"))
8269
if sys.platform == "win32":
83-
dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "Scripts")
84-
chromedriver_path = os.path.join(dest, "chrome", "chromedriver.exe")
85-
# By default Windows treats paths as case-insensitive
86-
path_fn = lambda path: path.lower()
70+
chromedriver_binary = "chromedriver.exe"
8771
else:
88-
dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "bin")
89-
chromedriver_path = os.path.join(dest, "chrome", "chromedriver")
90-
path_fn = lambda path: path
91-
if os.path.exists(chromedriver_path):
92-
os.unlink(chromedriver_path)
72+
chromedriver_binary = "chromedriver"
9373
# This is a stable version.
9474
binary_path = chrome.install_webdriver_by_version(
95-
dest=dest, version="115.0.5790.170", channel="stable")
96-
assert path_fn(binary_path) == path_fn(chromedriver_path)
97-
assert os.path.exists(chromedriver_path)
98-
os.unlink(chromedriver_path)
75+
dest=str(tmp_path), version="115.0.5790.170", channel="stable")
76+
assert os.path.samefile(
77+
binary_path,
78+
os.path.join(tmp_path, "chrome", chromedriver_binary),
79+
)
9980

10081

10182
@pytest.mark.slow
10283
@pytest.mark.remote_network
10384
@pytest.mark.xfail(sys.platform == "win32",
10485
reason="https://github.com/web-platform-tests/wpt/issues/17074")
105-
def test_install_firefox():
86+
def test_install_firefox(tmp_path):
10687
if sys.platform == "darwin":
107-
fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "Firefox Nightly.app")
88+
fx_binary = "Firefox Nightly.app"
10889
else:
109-
fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "firefox")
110-
if os.path.exists(fx_path):
111-
utils.rmtree(fx_path)
90+
fx_binary = "firefox"
11291
with pytest.raises(SystemExit) as excinfo:
113-
wpt.main(argv=["install", "firefox", "browser", "--channel=nightly"])
92+
wpt.main(argv=["install", "-d", str(tmp_path), "firefox", "browser", "--channel=nightly"])
11493
assert excinfo.value.code == 0
115-
assert os.path.exists(fx_path)
116-
utils.rmtree(fx_path)
94+
assert os.path.exists(os.path.join(tmp_path, "browsers", "nightly", fx_binary))

0 commit comments

Comments
 (0)