Skip to content

Commit

Permalink
test: Restore offending test, avoiding truly temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Aug 28, 2024
1 parent 79b9b07 commit 6aa137f
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import shutil
import sys
from pathlib import Path
from tempfile import TemporaryDirectory

import numpy as np
import pytest
Expand Down Expand Up @@ -117,26 +116,30 @@ def test_construct_backend(backend):
)


# @pytest.fixture
# def uninstall_qibojit():
# p = Path(qibojit.__file__).parent
# modules = list(sys.modules.keys())
# for mod in modules:
# if mod.startswith("qibojit"):
# del sys.modules[mod]
# with TemporaryDirectory() as tdir:
# shutil.move(p, tdir)
# yield
# shutil.move(Path(tdir) / p.name, p)
# importlib.import_module("qibojit")
#
#
# def test_default_backend(uninstall_qibojit):
# """Reproducing https://github.com/qiboteam/qibo/issues/1424."""
# # reset global backend
# GlobalBackend._instance = None
# # attempt loading
# default_backend = get_backend()
@pytest.fixture
def uninstall_qibojit():
p = Path(qibojit.__file__).parent
modules = list(sys.modules.keys())
for mod in modules:
if mod.startswith("qibojit"):
del sys.modules[mod]

# avoid using directly cwd since it would still in the PYTHONPATH
tdir = Path.cwd() / "tmp"
tdir.mkdir()
shutil.move(p, tdir)
yield
shutil.move(tdir / p.name, p)
tdir.rmdir()
importlib.import_module("qibojit")


def test_default_backend(uninstall_qibojit):
"""Reproducing https://github.com/qiboteam/qibo/issues/1424."""
# reset global backend
GlobalBackend._instance = None
# attempt loading
default_backend = get_backend()


def test_list_available_backends():
Expand Down

0 comments on commit 6aa137f

Please sign in to comment.