-
Notifications
You must be signed in to change notification settings - Fork 13
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
[JOSS] low and variable test coverage when running locally #32
Comments
This is strange. I guess different test suites have slightly different ways of measuring coverage, and the 91% value that is reported on the RayFlare repository is calculated by codecov and not pytest, but the difference in total coverage (91 vs. 52%) seems very extreme, especially since codecov is calculating the coverage based on the test report generated by pytest. The fact that the coverage fluctuates is even stranger. The ray-tracing tests are obviously stochastic in nature but I can't think of a reason that would change the actual lines of code that get hit or not hit. Some tests have inputs which are randomly chosen from a range but again I cannot think of a reason why that would change which parts of the code are accessed. So basically, I have no idea why this is happening but I will try running pytest coverage locally on my own computer to see if I have the same problem. |
I have just had a thought on why the RCWA coverage could be so different -- what OS are you running this on? For the GitHub Actions, because installing S4 is a pain and easiest on Linux, I am only installing it and running the tests associated with RCWA/S4 on Ubuntu, so they are marked to be skipped if the operating system is not Linux:
So if you delete these lines where they appear, it should run on your system (assuming S4 is installed). I need to check to be sure but this may well also affect coverage of TMM and RT-related files, since there are some examples which compare the different methods to see if they give consistent results, and if a test compares e.g. RCWA and TMM it will currently only run on Ubuntu so could also affect TMM coverage. Obviously, this isn't very good practice for writing tests, I should really have more unit tests which isolate these things and test smaller bits of code separately, but it might explain part of the issue, though it does not explain the fact that the coverage changes. |
Ah sorry, I should have mentioned that I was running it on a linux (debian) installation with S4 installed. If |
Ok, running things locally on my computer also gives a much lower % of coverage than reported by codecov, but it's not variable between runs. Will have a look later to see if I can figure out why the coverage % for some files is so different (and which one is correct...).
|
Speculation: perhaps it has something to do with multiprocessing and lines executed by worker processes not getting counted correctly. That could definitely make things behave differently run-to-run and between machines... |
Yes, good thinking. It also makes sense that in that case files which are covered separately (e.g. analytic/diffraction.py and angles.py) are consistent between my local run and the codecov report while the actual optical calculation parts which can happen in parallel are not. I will just make a new branch locally and switch all the calculations to not in parallel - this will definitely change the coverage somewhat, because obviously then the parts of the code for parallel execution will not be tested, but should give a more similar overall number if that is the cause. |
Ok, changing everything to run not in parallel improves the coverage somewhat (50% to 60%), but actually checking the coverage reports indicates that there is a more fundamental issue. For the rt.py, tmm.py and rcwa.py files, the coverage reports indicate that there is no coverage whatsoever of the RT, TMM and RCWA functions (i.e. the functions which generate matrices for the angular redistribution matrix method). This is incorrect, because these methods are used in several of the examples in test_compare_methods. The only thing I can think of is that codecov considers a part of the code covered if it is used while running the tests, and thus considers these functions (mostly) covered, while pytest imposes some more strict criterion, like that the function has to be called directly (which RCWA, TMM and RT are not -- they are called by process_structure in the test functions). |
I've made some partial progress here. I added a couple files in the repository root:
Then I calculate coverage with this sequence:
Name Stmts Miss Cover
-------------------------------------------------------------------------
rayflare/__init__.py 0 0 100%
rayflare/analytic/__init__.py 0 0 100%
rayflare/analytic/diffraction.py 63 22 65%
rayflare/angles.py 57 28 51%
rayflare/matrix_formalism/__init__.py 2 0 100%
rayflare/matrix_formalism/ideal_cases.py 48 4 92%
rayflare/matrix_formalism/multiply_matrices.py 261 7 97%
rayflare/matrix_formalism/process_structure.py 97 4 96%
rayflare/options.py 31 0 100%
rayflare/ray_tracing/__init__.py 1 0 100%
rayflare/ray_tracing/rt.py 613 139 77%
rayflare/rigorous_coupled_wave_analysis/__init__.py 1 0 100%
rayflare/rigorous_coupled_wave_analysis/rcwa.py 621 258 58%
rayflare/state.py 12 3 75%
rayflare/structure.py 40 5 88%
rayflare/textures/__init__.py 2 0 100%
rayflare/textures/define_textures.py 16 0 100%
rayflare/textures/standard_rt_textures.py 58 12 79%
rayflare/transfer_matrix_method/__init__.py 1 0 100%
rayflare/transfer_matrix_method/lookup_table.py 74 9 88%
rayflare/transfer_matrix_method/tmm.py 294 145 51%
rayflare/utilities.py 24 4 83%
-------------------------------------------------------------------------
TOTAL 2316 640 72% So there's progress, but still lower than what codecov is finding. Here's the full coverage report: htmlcov.zip. @phoebe-p maybe you can take a look at this report (or follow the above steps yourself) and see what you think? Hopefully it should be more accurate about what is actually getting run. I think this is beyond the scope of the JOSS review at this point -- I'm happy to continue helping figure this out, but I don't think there's any need to hold up the review for it. |
This is more of a question than an issue report. When I run the test suite locally and calculate coverage, I get a much lower number than what the CI finds. The biggest coverage differences are
rt.py
andrcwa.py
. The specific numbers also change from run to run (e.g. in another run,tmm.py
showed 99% coverage). I'm happy to dig a bit more to try to understand why, but I wondered if this behavior is expected. Here's the result of$ coverage html
: htmlcov.zip, and the corresponding test output:xref openjournals/joss-reviews#3460
The text was updated successfully, but these errors were encountered: