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
Class name detection fails for metaclass #93
Comments
I have never encountered metaclasses before today. It was fun to read up on them! This section of the Python docs define how to create a testcase:
Your metaclass subclasses I wouldn't be opposed to attempting to add a feature to green that omits metaclasses from discovery, but I can't find a way to detect whether a class is a metaclass in Python 3. In Python 2, it looks like I can just check for the presence of So...
|
You misunderstood our structure. We provide a Now I don't know what @jayvdb actually means with:
As all our test cases use a class which uses |
@xZise Yep, I didn't read that quite right. Your metaclass is not subclassing |
My limited analysis is that the underlying bug is in the "output name creation" process. The error is fixed when I change the names of the test methods, and even changing the order of the names helps. |
As an interested outsider I find it hard to understand this issue, even though I am using green with metaclassed @jayvdb / @xZise could you provide a reduced example (one stand-alone test file) that still reproduces and highlights what the problem is? |
@krisztianfekete have you used subclasses as well? |
Okay as you suggested I have tried to reduce the example drastically in https://gist.github.com/xZise/4f9e70910b020e2664ac You just need to install green and download those 4 files and execute:
The latter will work while the former will not work on Python 2.7. On Python 3.5 it does actually work. And please note that part of the code isn't actually valid (missing classes or imports) but they are never executed in the environment of the code. I'm trying to find more code which is not necessary. |
@xZise Thanks for trimming down the problem, I can reproduce now. @CleanCut I think it is related to the protocol on the queues between the runner and processes, but do not understand what's going on. I have tried to instrument
When uncommenting these two lines (38-39): https://gist.github.com/xZise/4f9e70910b020e2664ac#file-tools_tests-py-L38 it runs like this:
Note: the number of tests thought to be run in the latter case is wrong as well: it should be 4! |
Found it! This one was really tricky. Short version: Your Long version: Green assumed that you can't have two classes of the same name in the same module, since that's syntactically impossible in raw source code (the second definition would simply overwrite the first). We were using this "fact" to ensure we didn't double-run things by checking the string value of our class name. Green was dying at this check. It's a sanity check -- it shouldn't ever happen. So I started tracing backwards. How were we getting two identical classes?? I checked the class names of the testcase objects (the actual value of So I started looking into
and then you use name in your loop:
and finally you try to reuse name in your call to
The last value of This is why python also showed the buggy behavior (strange, duplicate class names of You can fix it by either changing the loop variable or the |
Very big thank you! |
The bug was fixed on our side: https://gerrit.wikimedia.org/r/#/c/250940/ \o/ |
Great! |
green reports an error when running a test case which uses a metaclasses, and also reports the wrong name for the test class. (see
__doc__
andgreen.result
appearing below)The top level entry
__doc__
in the above is a metaclassed test class, and it is failing to get the class name/docstring correct, but otherwise works OK:https://github.com/wikimedia/pywikibot-core/blob/master/tests/tools_tests.py#L521
Then the failure occurs on the 'next' test class, which inherits from the metaclass
https://github.com/wikimedia/pywikibot-core/blob/master/tests/tools_tests.py#L555
Returning to the
__doc__
entry, I can fix that by sorting the names of the methods being created in__new__
, e.g.causes the
green
output to beThe text was updated successfully, but these errors were encountered: