Skip to content

Commit 16f9ba4

Browse files
committed
launch_yaml: cache and restore test environment
Several of the launch_yaml tests mutate the os.environ variable, which can yield some unexpected results depending on the sequence the tests are run. Use a fixture to cache and restore the original environment. Signed-off-by: Michael Carroll <carroll.michael@gmail.com>
1 parent 57c1aee commit 16f9ba4

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

launch_yaml/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2026 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import pytest
17+
18+
@pytest.fixture(autouse=True)
19+
def restore_env():
20+
"""
21+
Restore environment after running tests.
22+
23+
Protects the environment when tests mutate or clear it.
24+
"""
25+
original_env = os.environ.copy()
26+
yield # The test runs here
27+
os.environ.clear()
28+
os.environ.update(original_env)

0 commit comments

Comments
 (0)