Closed BallisticBuddha closed 9 years ago
Thanks for the detailed bug report. I actually ran into this myself while testing #19. Here's how I fixed it in that pull request - what do you think?
@staticmethod
def thisFile():
"""Returns the basename of __file__ without a trailing 'c'"""
filename = os.path.basename(__file__)
if filename.endswith('.pyc'):
filename = filename[:-1]
return filename
#...
self.assertIn(self.thisFile(), d['location']['filename'])
Yep, that looks good, and is what I was talking about with my first suggestion by ignoring the last character in this instance.
Closed in #19.
This is mainly an issue for local development by running the unittests locally. Found with Python 2.7.6
To reproduce:
python -m unittest discover
test_autodoc.py
file, runpython -m unittest discover
againThis results in the following error:
This is due to the tests that verify the location property being run from the compiled .pyc bytecode, therefore making the source of the actual file running the test the .pyc file, which appears as the
__file__
attribute in this scenario.I can see three possible solutions to this:
self.assertIn(d['location']['filename'], __file__)
. This isn't as clear when read, but basically because the expected value '/path/to/project/test/test_autodoc.py' is contained in the string '/path/to/project/test/test_autodoc.pyc', it should pass the assertion.clean
of the environment by removing excess artifacts such as .pyc files.