-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
tests: refactor the test runner #434
Conversation
The current implementation, using the unittest.main function, is not working correctly with how kcov tests are loaded. One annoying problem is that filtering tests is not possible. Rewrite the test runner, adding a new libkcov package. The code from "testbase.py" is moved to libkcov.__init__ (the test API), and the code from "run-tests" is moved to libkcov.main (the test runner). In the test API, remove the configure method and the global variables, since the configuration paths are now processed by argparse as positional arguments. These paths are validated and then used to initialize each test case, that now has an __init__ method. In order to make running the tests convenient, add a __main__ entry point to the libkcov package. Rename the test names; "file.py" is renamed to "test_file.py", since this is the preferred naming conventions. Tests are loaded by a custom test loader, not derived from unittest.TestCase, since the code is really simple. Move the "cobertura.py" module to the libkcov package, but without the main code. The main code has been moved to "parse_cobertura", so that it can be used as a tool. The new implementation make is easy do separate the test API, test runner, tests and tools. In order to reduce the number of changes, in each test file libkcov is imported using as testbase. It will updated in a separate commit. Update the "ci-run-tests.sh" script to run the tests with `python -m linbkcov`. It is necessary to set the PYTHONPATH environment variable. The behavior of the new test runner implementation should be the same as the old one, with the difference that the order of tests is different. The new order is what users expect.
Ops, I forgot to pull #433. |
Woah, very nice, thanks a lot! The |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #434 +/- ##
=======================================
Coverage 65.68% 65.68%
=======================================
Files 58 58
Lines 4514 4514
Branches 4171 4171
=======================================
Hits 2965 2965
Misses 1549 1549 ☔ View full report in Codecov by Sentry. |
There are some problems github: Linux amd64 took a lot of time for installing the firefox snap. I have a few questions about
|
Originally I was thinking of adding a new For now I will keep |
Not sure, but better to make them executable then and cleanup ci.yml. Also looks like it's done in multiple places.
They used to run, but there is an issue with code signing on MacOS: when running kcov the first time, you'll get a popup with something like "The application kcov wants to control other processes, allow?". You'll need to accept this to run kcov, so the tests on MacOS are now disabled in the ci run (since I can't click the popup...). I haven't investigated very well if it's possible to accept via the CLI somehow.
Maybe, but as I said before, the system mode tests are not really relevant since it's barely half-implemented anyway. Better to just disable them I think. And yes, running as non-root is preferred. I don't remember if there was any particular reason to use sudo, but otherwise it can be turned off. |
For code signing I found
|
Yes, the first one sounds like the way to go. It needs to be signed though, since it uses non-standard "entitlements", i.e., acting as a debugger. Otherwise, the OS will not allow the ptrace etc calls. Anyway, that's a separate issue to this! |
The command line support was already added in 74cdbaa (tests: refactor the test runner). Just ensure that a plain string pattern is converted to fnmatch syntax, as done by unittest.main.
When enabled, randomize the execution order of tests, allowing support for detecting inter-test dependencies.
The new name is more descriptive, like sources.
The Kcov prefix is redundant, since after this change the qualified name will be libkcov.TestCase. Use "libkcov" as the name when importing libkcov, instead of using testbase (used for avoiding additional renaming in 74cdbaa).
The new method will make TestLoader more readable.
These are additional features that I planned to implement, but I think it is better to implement them in the test driver (like https://gist.github.com/perillo/cebd9f82094471b241b961a4f869b0ed), instead. What do you think about reimplementing it in Python and push to master, in Here are the additional features: add the
|
Yes, that sounds like neat features! Adding them in the Anyway, if you feel this PR is now ready, I'll gladly merge it |
Do you prefer the
For me it is ready to be merged. Thanks. |
I think I'd prefer test/tools |
As I am working on a kcov update for Fedora, I wanted to thank @perillo for his work on the test suite that I never had time to investigate. I'm done reviewing changes between the v42 and v43 tags and I'm almost positive that this pull request is the one that turns the table on my machine. It went from almost nothing working to this on my Fedora 40 laptop:
Running the test suite in an RPM build still fails, but much much less than before, when pretty much nothing used to pass:
The remaining failures are probably caused by compilation and linking hardening flags set on Fedora but again, no time to investigate. That's it, thanks again for your work on the test suite. |
@dridi and @SimonKagstrom, I'm glad that these changes are useful. There are still a few changes I would like to implement:
Unfortunately these change may introduce bugs. |
Refactor the tests
CHANGES
tests: refactor the test runner
The current implementation, using the
unittest.main
function, is not working correctly with howkcov
tests are loaded. One annoying problem is that filtering tests is not possible.Rewrite the test runner, adding a new
libkcov
package.The code from "testbase.py" is moved to
libkcov.__init__
(the test API), and the code from "run-tests" is moved tolibkcov.main
(the test runner).In the test API, remove the
configure
method and the global variables, since the configuration paths are now processed byargparse
as positional arguments. These paths are validated and then used to initialize each test case, that now has an__init__
method.In order to make running the tests convenient, add a
__main__
entry point to thelibkcov
package.Rename the test names; "file.py" is renamed to "test_file.py", since this is the preferred naming conventions.
Tests are loaded by a custom test loader, not derived from
unittest.TestCase
, since the code is really simple.Move the "cobertura.py" module to the
libkcov
package, but without the main code. The main code has been moved to "parse_cobertura", so that it can be used as a tool.The new implementation make is easy do separate the test API, test runner, tests and tools.
In order to reduce the number of changes, in each test file
libkcov
is imported using astestbase
. It will updated in a separate commit.Update the "ci-run-tests.sh" script to run the tests with
python -m linbkcov
. It is necessary to set thePYTHONPATH
environment variable.The behavior of the new test runner implementation should be the same as the old one, with the difference that the order of tests is different. The new order is what users expect.
tests: add support for test filtering
The command line support was already added in 74cdbaa (tests: refactor the test runner). Just ensure that a plain string pattern is converted to
fnmatch
syntax, as done by unittest.main.tests: add the
--shuffle
option to the test runnerWhen enabled, randomize the execution order of tests, allowing support for detecting inter-test dependencies.
tests: rename
testbuild
to binariesThe new name is more descriptive, like
sources
.tests: rename
KcovTestCase
toTestCase
The Kcov prefix is redundant, since after this change the qualified name will be
libkcov.TestCase
.Use "libkcov" as the name when importing
libkcov
, instead of using testbase (used for avoiding additional renaming in 74cdbaa).tests: add the
TestLoader.add_test_case
methodThe new method will make
TestLoader
more readable.Additional notes
tests: refactor the test runner
stat: 16 files changed, 251 insertions(+), 111 deletions(-)
Not sure if
parse_cobertura
works correctly, since I have not tested it@SimonKagstrom can you test it? Is it still used?
I named the package
libkcov
. A better name iskcov
(orktest
?), butimport kcov
may cause confusion withself.kcov
in the test case.I plan to rename
libkcov.KcovTestCase
tolibkcov.TestCase
A renaming is already needed, for renaming
import libkcov as testbase
toimport libcov
.I plan to rename
testbuild
tobinaries
.This is not necessary, but IMHO
binaries
seems a better name. Let me know if you agree.Originally I planned to move
cobertura
to a subpackage:but I changed idea, since I don't know if that code is still used, and
parse_cobertura
may be more convenient to use.tests: add the --shuffle option to the test runner
After running a the tests with the
--shuffle option
, I got two error (in two separate runs):I encountered the
test_bash_linux_only.bash_sh_shebang.runTest
failure a few time with the old test runner, usually when some other test failed.