Skip to content

Commit

Permalink
Reload pydantic before and after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayP13 committed Dec 26, 2023
1 parent 81550c1 commit 2cd2b20
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/tests/llms/test_llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
OPENAI_TREE_CHAT_ANSWER = "Trees can be various shades of green, but they"


def _reload_pydantic():
for m in list(sys.modules.keys()):
if m.startswith("pydantic"):
del sys.modules[m]


class TestLLM:
def test_import(self):
from concurrent import futures
Expand Down Expand Up @@ -2104,13 +2110,12 @@ def setup_class(cls):
cls.pydantic_version = importlib.metadata.version("pydantic")
os.system("pip3 install petals==2.2.0")
os.system("pip3 install 'pydantic>=1.10,<2.0'")
for m in list(sys.modules.keys()):
if m.startswith("pydantic"):
del sys.modules[m]
_reload_pydantic()

@classmethod
def teardown_class(cls):
os.system(f"pip3 install pydantic=={cls.pydantic_version}")
_reload_pydantic()

def test_init(self, create_datadreamer):
with create_datadreamer():
Expand Down Expand Up @@ -2443,10 +2448,12 @@ class TestTogether:
def setup_class(cls):
cls.pydantic_version = importlib.metadata.version("pydantic")
os.system("pip3 install together==0.2.10")
_reload_pydantic()

@classmethod
def teardown_class(cls):
os.system(f"pip3 install pydantic=={cls.pydantic_version}")
_reload_pydantic()

def test_warnings(self, create_datadreamer):
with create_datadreamer():
Expand Down Expand Up @@ -2624,10 +2631,12 @@ class TestMistralAI:
def setup_class(cls):
cls.pydantic_version = importlib.metadata.version("pydantic")
os.system("pip3 install mistralai==0.0.8")
_reload_pydantic()

@classmethod
def teardown_class(cls):
os.system(f"pip3 install pydantic=={cls.pydantic_version}")
_reload_pydantic()

def test_init(self, create_datadreamer):
with create_datadreamer():
Expand Down

0 comments on commit 2cd2b20

Please sign in to comment.