-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Unitests: move environment setup from run_unitests.py to test fixtures #14367
base: master
Are you sure you want to change the base?
Unitests: move environment setup from run_unitests.py to test fixtures #14367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from being more correct, this allows running tests without the runner to be more useful, namely if one wants to invoke
pytest
orpython -m unittest
directly.
I have some skepticism of this PR, mostly because I do not understand why you think you should be doing this.
This will allow all tests, even those that don't need all of the helpers provided by the BasePlatformTest to still shared some of the environment setup from other tests.
While the Cargo and TAP tests do not invoke parts of Meson that need specific environment setups, several other tests do not get those setups but need them.
…_unitests.py These are expected state setup for the test cases, not argument handling for the run_unittests script, as such they should be handled through test fixtures not through the run unittests script. This makes a bare run of "pytest" and "./run_unitests.py" with pytest installed basically equivalent (though without the automatic addition of some arguments passed by run_unittests.py.
010a8b7
to
e0e0aa0
Compare
Because I want to use standard tools in the standard way rather than through a project specific wrapper script. run_unitests.py offers me 0 advantages over running pytest directly (except for this case of test environment setup being done in the wrapper instead of in a test fixture where it belongs, so it papers over a bug), and numerous disadvantages, among them:
Rather than trying to make this custom wrapper not terrible for me as a developer, I can just accept that it isn't meant for me to use as a developer, it's meant to make running our unittests in CI work well, a job it is doing just fine at. |
Can you demonstrate for example how to implement --backend without |
I'm honestly frustrated with the whole discussion, because it feels like we're blocking what is clearly an improvement in the form "use test fixtures to ensure that the environment matches the test expectations" on what feels to me like animosity toward me not wanting to use |
I just think it feels overengineered. :/ #13423 attempted the same thing, but by moving "test harness" setup to |
Well, I really wanted to move to pytest because pytest has global fixtures, not just test and class fixtures. These are class fixtures, so they're only run once per class and not per test. |
They may be run once per test, if tests from different classes are interleaved together. There are some plugins that do this automatically whenever they are installed, so you might not even realize that's what happened. |
We can't really "move" to pytest because it is not in the stdlib. Plain |
Even if meson cannot require more than the stdlib to run, that would not exclude relying on pytest or other external Python-only wheels for the purpose of running tests, would it? |
I've found it useful in the past to be able to run the self-tests on systems without pytest installed. In particular, running against additional python interpreter versions, where pytest was only packaged / installed for a single (default) python. Requiring pytest would make it a hassle for me to do cpython alpha testing. |
I understand the reasons why we're not going to, but it's pretty frustrating because |
Stack overflow has some suggestions on global setup/teardown for unittest, I'll have to try those in a bit. |
We really don't see that here. :) A pytest session fixture is often overly complicated as opposed to just running code at startup. The point of fixtures is to tag them for use on specific tests (by passing them as magic test function arguments), which allows you to do things like have a fixture that runs only once per pytest run, but only right before the first function that uses that fixture, and avoid running the fixture if you don't run any tests that use the fixture (only tests that don't use it). It's trivial to remap the current environment setup into an |
What I mean is, there's a mechanism unittest provides for a global setup/teardown you put in your |
We currently have the
run_unttests.py
removing certain environment variables (CFLAGS and friends) before starting tests, because some tests do not behave correctly when they are set. The right place to do this is an a test fixture, particularly insetUpClass
.To facilitate this, a new base class has been added that adds this setup through a mock, and several test classes that should have this setup have been extended to use it. Then the environment setup is moved into the fixture.
Apart from being more correct, this allows running tests without the runner to be more useful, namely if one wants to invoke
pytest
orpython -m unittest
directly.