-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Weird test names in pytest -v output #804
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
Comments
Could you provide a reproducible example? I found the code responsible for that, but couldn't reproduce it myself with some limited testing. |
You can try with this GitHub project https://github.com/Yelp/pyleus This is the pastebin of my output |
Thanks, I'll try that later! Could post also what was the exact command you did, and what was the current directory? |
I'm in the top directory of the project. I run |
After some digging and analyzing the code you provided, I could narrow down the problem with this simple test: # contents of test_foo.py
import os
import mock
class TestConfiguration(object):
@mock.patch.object(os.path, 'exists', autospec=True)
def test_validate1(self, *args):
pass
def test_validate2(self):
pass Executing
Commenting out the line with the
Applying It's due to I've opened a PR in Long DescriptionIt boils down to the fact that def reportinfo(self):
# XXX caching?
obj = self.obj
if hasattr(obj, 'compat_co_firstlineno'): # <--- when mock.patch decorator is used
# nose compatibility
fspath = sys.modules[obj.__module__].__file__
if fspath.endswith(".pyc"):
fspath = fspath[:-1]
lineno = obj.compat_co_firstlineno
else: # normal cases
fspath, lineno = getfslineno(obj)
modpath = self.getmodpath()
assert isinstance(lineno, int)
return fspath, lineno, modpath When the mock.patch decorator is applied, the code above will return a Next the code that returns a def location(self):
# <snip>
fspath = self.session.fspath.bestrelpath(location[0])
cache[location[0]] = fspath
location = (fspath, location[1], str(location[2]))
self._location = location
return location This in turn makes the terminal code think that the collected path and item path are not the same, and shows that distinction in the output: def _locationline(self, nodeid, fspath, lineno, domain):
# <snip>
if fspath:
res = mkrel(nodeid).replace("::()", "") # parens-normalization
if nodeid.split("::")[0] != fspath.replace("\\", "/"):
res += " <- " + self.startdir.bestrelpath(fspath)
else:
res = "[location]"
return res + " " 😅 |
Thanks for looking into this! :) |
@nicoddemus what's the state on this one? |
It was supposed to be fixed in this PR, but it got dropped... I suggest we drop this until this crops up again. |
@nicoddemus how about your https://bitbucket.org/pytest-dev/py/pull-requests/31? Are you going to reopen it again? I see the problem was just hg and not your code... |
we want to drop py.path in the long term anyway, so i wonder how we should attack this |
Is just a bug fix, I think we should just re-apply it once #1199 is merged. |
@nicoddemus cool, thanks! |
This happened to me on at least three different projects when running
pytest -v
. Some of the test cases constantly appears in this weird forminstead of the usual one.
I tried to look for something similar in the documentation, but I wasn't able to find anything. I can't spot any difference between the "weird" test cases and the regular ones.
Does anyone knows what's going on here?
The text was updated successfully, but these errors were encountered: