-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
How to reset qapp_args for each test class? #514
Comments
I think the fixtures should have scope |
I think it might not be possible to change the pytest-qt/src/pytestqt/plugin.py Line 66 in 0518ca0
or retrieves a previously stored instance pytest-qt/src/pytestqt/plugin.py Line 63 in 0518ca0
As I understand, the command line arguments are passed to the |
If this is true, one should try do this differently. For example using the mocker fixture:
|
You got the gist of it: QApplication can only be instantiated once per process, after that you cannot really change its arguments. If you need to test this somehow, you will probably need to restructure your code a bit and use mock. Closing for now, I assume there is nothing actionable for pytest-qt here. |
Note that you can simplify this a bit by using monkeypatch which is built into pytest: class Test1:
def test_pos_args(self, qapp, monkeypatch):
monkeypatch.setattr(QCommandLineParser, "positionalArguments", lambda: ["a1"])
args = get_positional_args(qapp)
assert len(args) == 1
class Test2:
def test_pos_args(self, qapp, monkeypatch):
monkeypatch.setattr(
QCommandLineParser,
"positionalArguments",
lambda: ["a1"], ["a2"]
)
args = get_positional_args(qapp)
assert len(args) == 2 |
@The-Compiler Thanks for the tip!! |
I would like to run each test class with a different set of command line arguments (
qapp_args
fixture), here is a minimal example:But in the second test class
Test2
overridingqapp_args()
does not work. It seems like it is using theqapp_args()
defined in theTest1
class instead. How can I solve this?The text was updated successfully, but these errors were encountered: