Closed symwell closed 1 year ago
I thought it was because
test_case id is unittest.loader._FailedTest.polls.tests
and it extracts as test id only the last token tests
instead of perhaps polls.tests
method_name = test_case.id().split(".")[-1]
But after changing this logic in a few ways it didn't fix it.
This actually turns out to be a weirdness in the test runner (or maybe unittest
itself).
The problem is that the user added the line
from appmap.unittest import TestCase
to the top of their test file, but there's no TestCase
in appmap.unttest
:
ajp@Alans-MacBook-Pro django-polls % head polls/tests.py
import datetime
from appmap.unittest import TestCase
from django.urls import reverse
from django.utils import timezone
from .models import Question
class QuestionModelTests(TestCase):
(django-polls) appmap-testcase
ajp@Alans-MacBook-Pro django-polls % python
Python 3.10.8 (main, Oct 14 2022, 08:08:42) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from appmap.unittest import TestCase
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TestCase' from 'appmap.unittest' (/Users/ajp/.local/share/virtualenvs/django-polls-RIoQgNjI/lib/python3.10/site-packages/appmap/unittest.py)
Instead of telling the user this, the runner continues until it blows up with the above error.
If appmap.unittest
doesn't have TestCase then it would be nice if you could update your documentation with symwell's example.
I was very confused and perplexed that I would have to use appmap.unittest.TestCase
since Django has its own TestCase that subclasses from unittest.TestCase
.
If the example from @symwell was part of the doc then the misunderstanding wouldn't occur =)
Thanks very much for your input, I agree that the doc is pretty terse. We'll get it updated with an example.
Running
APPMAP=true python manage.py test
in the repository https://github.com/Antylon/django-polls on branchappmap-testcase
produces the error