Skip to content

Commit 6c62066

Browse files
committed
refactor: Mock environment variables
1 parent c39a785 commit 6c62066

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

tests/test_version.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
import os
22
import unittest
3+
from unittest.mock import patch
34

45
import pystac
56
from tests.utils import TestCases
67

78

89
class VersionTest(unittest.TestCase):
910
def setUp(self) -> None:
10-
self._prev_env_version = os.environ.get("PYSTAC_STAC_VERSION_OVERRIDE")
11-
self._prev_version = pystac.get_stac_version()
12-
13-
def tearDown(self) -> None:
14-
if self._prev_env_version is None:
15-
os.environ.pop("PYSTAC_STAC_VERSION_OVERRIDE", None)
16-
else:
17-
os.environ["PYSTAC_STAC_VERSION_OVERRIDE"] = self._prev_env_version
18-
pystac.set_stac_version(None)
11+
pystac.version.STACVersion._override_version = None
1912

2013
def test_override_stac_version_with_environ(self) -> None:
21-
2214
override_version = "1.0.0-gamma.2"
23-
os.environ["PYSTAC_STAC_VERSION_OVERRIDE"] = override_version
24-
cat = TestCases.test_case_1()
25-
d = cat.to_dict()
15+
with patch.dict(os.environ, {"PYSTAC_STAC_VERSION_OVERRIDE": override_version}):
16+
cat = TestCases.test_case_1()
17+
d = cat.to_dict()
2618
self.assertEqual(d["stac_version"], override_version)
2719

2820
def test_override_stac_version_with_call(self) -> None:

0 commit comments

Comments
 (0)