Skip to content

test_util: Implement test for get_combobox_index_by_value #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025

Conversation

sonic2kk
Copy link
Contributor

This PR implements a unit test for the get_combobox_index_by_value utility function.

I tested this test with and without the QT_QPA_PLATFORM=offset environment variable. It's worth noting that we set this environment variable in CI.

When running multiple tests that use a QApplication, I was running into an error along the lines of Please destroy the QApplication singleton before creating a new QApplication instance. This would happen if a test created a QApplication() and then another test tried to do the same thing.

Trying to fix this took a bit of research. I stumbled across this comment on a thread that suggested using QApplication.shutdown(). This resolved the problem.

Thanks!

@sonic2kk
Copy link
Contributor Author

sonic2kk commented Apr 13, 2025

I was taking a look at another test that requires a QApplication instance (ghapi_rlcheck util) and it needs the message_box_message. To solve this we can instantiate a PupguiApp object, which is a child of QApplication.

I wonder if this is a better approach, and if we should have a PupguiApp as a fixture for all tests? Usage is entirely the same, except we use app = PupguiApp(). Even the teardown is the same it seems, no need to use PupguiApp.shutdown or anything like that (Tested with two tests that use a PupguiApp instance locally).

@DavidoTek
Copy link
Owner

QT_QPA_PLATFORM=offset

Do you mean QT_QPA_PLATFORM=offscreen? Then that's correct.

I wonder if this is a better approach, and if we should have a PupguiApp as a fixture for all tests?

I think we have to do that. ghapi_rlcheck/glapi_rlcheck would crash otherwise, in the case of a rate limit.

While reviewing the "test" PRs, I just noticed how many side effects some of our functions have. That's making testing a bit complicated and possibly unpredictable...

@DavidoTek DavidoTek merged commit a6cdf72 into DavidoTek:main May 22, 2025
2 checks passed
@sonic2kk
Copy link
Contributor Author

Ah, apologies! Yes, I did mean offscreen.

While reviewing the "test" PRs, I just noticed how many side effects some of our functions have. That's making testing a bit complicated and possibly unpredictable...

Which side-effects are you thinking of? Is this around the QApplication? Just interested, as locally testing has been fine for me, but there may be a scenario I am not thinking of :-)

@DavidoTek
Copy link
Owner

Which side-effects are you thinking of? Is this around the QApplication? Just interested, as locally testing has been fine for me, but there may be a scenario I am not thinking of :-)

I was mainly thinking about the signals such as message_box_message or download_progress_percent. I just checked and they are only used for user interaction (displaying the message box, updating the UI). So my concern about unpredictable behavior with them might not be valid.

Another point I was wondering about is how far the state is shared between tests. As you pointed out, the QApplication instance persists across tests if not shut down manually. I don't think this has any impact at the moment, but that is something that should be kept in mind when working with Qt stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants