Skip to content

pytest: Clear env variables #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ current
- :issue:`303` Add ``common.get_libtmux_version`` which gives the tmux
version as a loose constraint. Fix linking to terms inside docs, and
duplicate description of module which sphinx warned about in api.rst.
- :issue:`266` Fix issue on local tests where env variables would cause
show-environment to pause tests indefinitely.
- *Insert changes/features/fixes for next release here*

libtmux 0.8.4 (2020-10-25)
Expand Down
32 changes: 31 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import logging
import os

import pytest

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


@pytest.fixture(autouse=True)
def clear_env(monkeypatch):
"""Clear out any unnecessary environment variables that could interrupt tests.

tmux show-environment tests were being interrupted due to a lot of crazy env vars.
"""
for k, v in os.environ.items():
if not any(
needle in k.lower()
for needle in [
'window',
'tmux',
'pane',
'session',
'pytest',
'path',
'pwd',
'shell',
'home',
'xdg',
'disable_auto_title',
'lang',
'term',
]
):
monkeypatch.delenv(k)


@pytest.fixture(scope='function')
def server(request):
def server(request, monkeypatch):

t = Server()
t.socket_name = 'tmuxp_test%s' % next(namer)

Expand Down