Skip to content

Commit

Permalink
Finally fix the problem with contaminated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teekuningas committed Mar 1, 2024
1 parent 267a5d7 commit 590a103
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ check:

.PHONY: test
test:
pytest --forked
pytest

.PHONY: update_docs
update_docs:
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
black
pylama
pytest-forked
pytest
pytest-qt
mkdocs
coverage
27 changes: 18 additions & 9 deletions meggie/utilities/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,21 @@ def patched_logger_exception(msg):
class BaseTestAction:
@pytest.fixture(autouse=True)
def setup_common(self, qtbot, monkeypatch):
# before each test
os.environ["QT_QPA_PLATFORM"] = "offscreen"
self.qtbot = qtbot
self.monkeypatch = monkeypatch
self.mock_main_window = MockMainWindow()
with tempfile.TemporaryDirectory() as tmpdirname:
self.dirpath = tmpdirname
self.setup_experiment()
yield
self.temp_dir = tempfile.TemporaryDirectory()
self.dirpath = self.temp_dir.name
self.setup_experiment()
yield
# after each test
self.temp_dir.cleanup()
for widget in QApplication.topLevelWidgets():
if widget.isWindow():
widget.close()
widget.deleteLater()

def setup_experiment(self):
self.experiment = create_test_experiment(self.dirpath, "test_experiment")
Expand Down Expand Up @@ -337,19 +344,21 @@ def patched_plt_show(*args, **kwargs):
)

# call the action handler
merged_data = {"tab_id": "test_tab"}
merged_data.update(data)
data = data.copy()
data.update({"tab_id": "test_tab"})
action_spec = load_action_spec(action_name)
self.action_instance = handler(
self.experiment, merged_data, self.mock_main_window, action_spec
self.experiment, data, self.mock_main_window, action_spec
)
return self.action_instance.run()

def find_dialog(self, dialog_class):
dialog = None
count = 0
for widget in QApplication.topLevelWidgets():
if isinstance(widget, dialog_class):
count += 1
dialog = widget
break
assert count == 1

assert dialog is not None
return dialog

0 comments on commit 590a103

Please sign in to comment.