Skip to content

Commit c01d063

Browse files
committed
pytest: Clear env variables
1 parent ce5e34c commit c01d063

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/conftest.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import logging
4+
import os
45

56
import pytest
67

@@ -11,8 +12,37 @@
1112
logger = logging.getLogger(__name__)
1213

1314

15+
@pytest.fixture(autouse=True)
16+
def clear_env(monkeypatch):
17+
"""Clear out any unnecessary environment variables that could interrupt tests.
18+
19+
tmux show-environment tests were being interrupted due to a lot of crazy env vars.
20+
"""
21+
for k, v in os.environ.items():
22+
if not any(
23+
needle in k.lower()
24+
for needle in [
25+
'window',
26+
'tmux',
27+
'pane',
28+
'session',
29+
'pytest',
30+
'path',
31+
'pwd',
32+
'shell',
33+
'home',
34+
'xdg',
35+
'disable_auto_title',
36+
'lang',
37+
'term',
38+
]
39+
):
40+
monkeypatch.delenv(k)
41+
42+
1443
@pytest.fixture(scope='function')
15-
def server(request):
44+
def server(request, monkeypatch):
45+
1646
t = Server()
1747
t.socket_name = 'tmuxp_test%s' % next(namer)
1848

0 commit comments

Comments
 (0)