Simplify the adoption of python tests by proving some example tests, utilising commonly-used patterns.
Details
- Reviewers
- None
- Group Reviewers
tests network - Commits
- rG176e0427b208: testing: add python test examples
rG8161b823d77f: testing: add python test examples
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Thank you!
Certainly, much better than a wiki.
Is this the desired output:
https://cirrus-ci.com/task/6234303340740608 ?
tests/examples/Makefile | ||
---|---|---|
6 | I believe this directory is not created when make all install standalone? but that is tangential to this revision. I suspect ATF_TESTS_PYTEST. | |
tests/examples/test_examples.py | ||
42 | ||
99 | There has been a preference lately for RFC 5737 addresses, to avoid a possible clash with a private IP currently in use. | |
115 | ||
178 | ||
186 |
Couple more nits.
New run (this time as expected):
https://cirrus-ci.com/task/5756291799842816?logs=test_examples
I'll eventually add a simple example that consumes Scapy directly (instead of doing it via a shell script).
tests/examples/test_examples.py | ||
---|---|---|
54 | ||
67 |
Thank you!
From my perspective, this is an excellent intro to testing.
tests/examples/Makefile | ||
---|---|---|
6 | But, besides that, I believe ATF_TESTS_PYTEST does not create the directory. If we use a C- or a shell-based ATF_TEST, it'll work. I see a message about it not stripping the .py extension, but I need to investigate more. | |
tests/examples/test_examples.py | ||
54 | May I ask, why do you keep this line commented out? |
This looks great. I especially like the ability to parameterize test cases, which isn't easy with atf-sh-api or atf-c-api. What about cleanup? I think atf-python tests need to do that differently, right? It would be good to add an example for that.
Thank you!
Yes, the cleanup is different from the native pytest approach. The initial driving usecase was to enable cheap VNET-run tests, where the cleanup procedures are fixed - you need to remove the jail & interfaces. That part is done automatically by the framework.
I'll add a hook that'll check if the test_name_cleanup() method exists and calls it to perform the cleanup, along with the example here. Does it look reasonable to you?
tests/examples/Makefile | ||
---|---|---|
6 | My current (limited) understanding is the following:
| |
tests/examples/test_examples.py | ||
54 | Sure, two reasons.
Guess it's time to do to just that - as it turns out I need this one for netlink testing. So, I'd say it's worth keeping as is untils at least one of two issues get resoled. Thoughts? |
A "test_case_cleanup" method would work. But it would be more Pythonic if it were a teardown method. Would that be possible?
tests/examples/test_examples.py | ||
---|---|---|
54 | No. If the "unprivileged_user" isn't set in /usr/local/etc/kyua.conf, then Kyua should skip the test. So I still think you should uncomment that line. |
While on this topic, the cleanup for the native pytest approach is done the "old" way. I have encountered a few races, where an epair interface remains after a massive test failure. In other words, I was contemplating the possibility of adapting 80fc25025ffcb0d369fc0b6d4d272ad6fd3f53c3, which destroys the epair assigned to the vnet from inside the jail. Obviously, this has nothing to do with this introductory tutorial.
tests/examples/Makefile | ||
---|---|---|
6 | My understanding is even more limited! I was just trying to take a shortcut. | |
tests/examples/test_examples.py | ||
54 | Yes, I see. Thanks for the detailed explanation. I wasn't aware of all those details. |
Yep, thanks for reminding! There is a known problem resulting from a corner case in the kernel delayed object reclamation model. I promised glebius@ to alter the mechanism as a workaround, but haven't done it yet. That's something that indeed needs to happen. I'll fix this in a day or two.
tests/examples/test_examples.py | ||
---|---|---|
54 | I looked at the code to refresh that part. If @pytest.mark.require_user("unprivileged") is set,
2.1 pass require.user="root" Does it sound reasonable? |
tests/examples/test_examples.py | ||
---|---|---|
54 | Re uncommenting - will do. Let me come up with the unprivileged-user fix first. |
Whoops. Sorry, I missed that comment. It landed as "cleanup_test_case" to mimic the generic "cleanup" method that already exists. That method was modelled after kuya.
I tried to make the framework abstracted from kuya/atf, but that part indeed slipped through the cracks. I'll come up with a separate renaming review next week if the time permits.
Meanwhile the per-test cleanups landed, with an example provided in this diff. Hope it does work for you :-)
tests/examples/test_examples.py | ||
---|---|---|
54 | Uncommented. I've published D37923 to address the dropping-privileges issue. |
I'm going to commit it as is for now and address the remaining issue in the follow-up commits.