-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add apt parser sub_package #2
Conversation
Christophe, I tried your new branch but when I ran the unit tests the test_templates.py module failed with the following error message: $ python test_templates.py |
Was still using the old standalone package apt_parser while it was supposed to use this new one
I can't reproduce your bug. But I found other problems when trying to reproduce: My imports were still using the old package instead of the new one, since both were installed in the same environment (miricle.devel). I then created a specific virtual envs to test it. But I realized that python setup.py develop doesn't work with this package, do you know if there's a way to use it without having to install everything each time I change something? Since the "miri" level doesn't exist, every symbolic link fail to reproduce the package structure, and "import miri" doesn't work. I'm sure you must have more experience than me on this.
I tried nosetests, to try and reproduce the bug and got:
|
I think I've found why the test fail when you try to launch it. You try to launch it directly with Python:
while if you try with pytest, it works:
|
Christophe, This shouldn't be a problem in the short term, since Jenkins is configured to use pytest. Is it possible to trap the exception and report a more informative error message (such as "Please launch this test using pytest, since it depends on pytest utilities") so that if Jenkins is modified in the future, or if anyone else tries to run the test directly, as I did, they will know what is happening. |
Steven, To be honest, I don't know how to change my test to put an error message. Because the error comes from internal code that is launched with the command:
I don't know what exactly python is doing when this command is ran. At the start of my script, there is an If you have an idea, I'm open to suggestions. Finally, I don't even know if nosetest fail to launch this test. When I tried, I get an error with setup.cfg unknown option "with-xcoverage" |
Christophe, By the way, it is only the test_dithering.py module which fails. The other modules successfully run their tests when I launch them with, for example python test_templates.py What's the difference between test_dithering.py and the other modules? If you could give test_dithering.py the same structure as the other modules, the issue goes away. The test fails at line 71 of test_dithering.py, so the kind of trap I am thinking of would be something like this: print("Running {}".format(func.name)) It reports the exception but adds a suggestion to try again using pytest. |
The "unknown option "with-xcoverage" error is an entirely separate issue. The following advice is contained in the README file: TESTINGThe unit tests included with the MIRI software can be run from the nosetests from the top-level installation directory. If nosetests complains about conda install nosexcover Individual tests can also be run from within the "tests" directory. cd MiriTE/datamodels/tests |
I've installed nosexcover and nosetests still gives me the same error:
I'm using Python 3.6.8, nosexcover v1.0.11 and nosetests v1.3.7 Now I understand the problem for the tests. It all comes from the |
(pytest.parametrize not handled in that case)
I've updated the test. But this will not be used with nosetests. I've looked at alternative for parametrize tests with nosetests, with nothing obvious as a replacement. I've also tried to run nosetests on that particular test, but it says that "miri" doesn't exist while I can import it in python. I'm not sure to understand this error:
|
I would be cautious about error trapping in unit test modules, since it could interfere with the purpose of unit tests. You probably want to make sure to re-raise the exact same kind of error, including the original traceback. You probably also should test what happens if an actual error of that kind were to occur in the module that the unit test is covering. |
No problem with the catch, it happens only in the
When using pytest, it shouldn't reach that part, and fail beautifully if needs be. |
That's a good point. It was the reason why I reraised the same exception and included the "str(e)" in the exception message to display the actual exception. Would the following code provide a safer solution? (import logging and create logger) try: This code traps the exception, displays a log message giving the user a hint and reraises the same exception. |
I found a typo in setup.py, which contains the following lines when defining the packages:
and should contain the following lines:
The "miri" level is missed from the package definition. This may be causing your "No module named 'miri'" error message. |
Originally, this was like this, but when i tried to install the package, I got the message "miri/" doesn't exist. I found that removing this solved my issue, which is why I removed it in a later commit. If I add what you propose, I get the following error when trying to install miri:
|
I pulled your latest updates and the package now appears to be working. I can build MiriTE successfully and run pytest. The package definition strings contain a "miri." as expected, so my previous comment was a mistake. You already made the changes necessary to setup.py. |
For information, when I run the 4 test scripts directly using Python I get the following behaviour: $ python test_library.py $ python test_templates.py $ python test_dithering.py The above exception was the direct cause of the following exception: Traceback (most recent call last): Two scripts give no output, one works, and it is only test_dithering.py which fails. The latest error message gives more information. It's an attempt to access pytest.parameterize which fails. Perhaps test_dithering.py is the only module to use that facility? I am wondering if this is a miricle/conda compatibility issue? |
This is not a miricle/conda compatibility issue. When you do:
you essentially use a piece of code I wrote to launch the test manually. This piece of code doesn't handle parameters, and simply fail. This is not a problem of Pytest, or Nosetests, or Python. This is just a bad piece of code I wrote month ago without ever using it after. I would be in favor of just deleting this piece of code. We're not supposed to launch unit test like this and I since then understood that. I don't write that anymore in any of my unit tests, but it somehow got stuck here. The two file you mention that don't have any output simply don't do anything when you attempt to run them, because they don't have my "bad piece of code" in it. When run with |
My mistake. I just noticed the "pytest.parametrize not supported" message is something your code reports, rather than something coming from within pytest itself. |
I checked and the parameterized package exist. It's supposed to work with nosetests, pytest and unittest. Unfortunately the current version doesn't work with pytest because yield is deprecated in pytest 4. That means all parameterized tests are skipped for now. I don't know when they expect to fix the package. A branch pytest4 exist for solving that issue. It seems adressed but is not yet merged into trunk (wolever/parameterized#34 ). Once it works, a fix would be:
|
@smbeard : Do I need to do something about this branch? Do I need to rewrite completely the parameterized test to a manual loop, even if it's not ideal, just to make the test work in this framework? |
Sorry about the long delay in replying. When I run nosetests after building the apt_parser branch the test fails with the following error messages: EE.EEE...E.......ERROR: Test of ditheringTraceback (most recent call last): ======================================================================
|
utils.read_test_xml function was causing nosetests to crash because there's the word 'test' in the function name
I've finally understood why the tests failed. I had a function named read_test_xml in utils.py, and this function was imported in the tests (used to read a fake xml and mimic the real process). It turns out that nosetests was thinking the whole time that this function was a test, just because there is "test" in the middle of it. Pytest was correctly ignoring this function, explaining why there was a difference between the two. I've successfully ran nosetests on my package this time:
I'm still working on the "mirisim" problem. But the test will be specific to nosetests running pytest. I can't make tests working for nosetests and pytest. |
I'm stucked on a problem I don't really understand, @smbeard if you have an idea, I could use some help on this one. The following are tests done in an environment without mirisim, to mimick what jenkins is doing.
I suppose an extra file is found that nosetests consider as a test, but I couldn't find another file or function containing "test", and even the line:
Note that I designed my package to keep mirisim dependant functions in a subpackage that is not imported by default. Meaning that mirisim dependency must happen only when the user tell specifically: |
Your latest commit now fails with this error message test_dithering.py:1: in The "parameterized" module is no longer recognised. Last week I upgraded my MIRICLE build to test whether Bug 575 could be closed. It looks like "parameterized" has been missed from the latest MIRICLE build. |
When I run nosetests -v --collect-only it lists the following files within apt_parser:
I wonder if your one remaining ImportError is coming from mirisim/init.py. Addendum: git has changed _ _ init _ _.py to init.py. |
I wonder why nosetests is running them. If it stays like this, I don't even know where to start and what to do with my apt_parser.mirisim sub-package. In the end, I still need mirisim functions for my package to work and run simulations. |
I'm wondering if the problem is coming from the coverage part of nosetests, because he tries to import everyhing, even if not asked. Is it possible to constrain where the tests need to be, like apt_parser/tests, and not elsewhere? If not, I'm afraid this merge will never be possible. (or if you have a solution, I'm open to it) |
I've deleted the mirisim part that is now included in the branch apt_parser of MIRISim. No merging problem anymore. |
Note also that I did not found a requirements.txt to ensure all my dependencies for apt_parser were covered by miri dependencies. I think about the package parameterized in particular. Steven, if there is a way to specify the list of package dependencies, could you please tell me were it is? (incidently, I also have the same question for mirisim) |
In this branch, I added my apt_parser package into MiriTE.
First commit, I just add the corresponding file
Second commit, I include apt_parser into the setup.py to make it installable.
See http://www.miricle.org/bugzilla/show_bug.cgi?id=573 for context.
The original package is here: https://git.ias.u-psud.fr/JWST/apt_parser