[Django] #28869: Django.test.tag Inconsistent Inheritance

12 views
Skip to first unread message

Django

unread,
Nov 30, 2017, 5:25:21 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-------------------------------------+-------------------------------------
Reporter: William | Owner: nobody
Ayd |
Type: Bug | Status: new
Component: Testing | Version: 1.11
framework |
Severity: Normal | Keywords: testing, tag
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When subclassing test cases, decorated tags are inherited ONLY when the
subclass does not provide its own tag decorator. If the subclass provides
its own decorator(s) then the parent's tags are ignored.

If you use the attached file, running:

{{{
python manage.py test
}}}

yields two test cases as expected. However, running

{{{
python manage.py test tag=foo-tests
}}}

OR

{{{
python manage.py test tag=baz-tests
}}}

Will each only run one test a piece. I would expect that the former would
run both test cases, given all of the test cases in the attached file are
inherited from a class which is decorated with that tag.

--
Ticket URL: <https://code.djangoproject.com/ticket/28869>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 30, 2017, 5:25:56 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+--------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by William Ayd):

* Attachment "test_foo.py" added.

test_foo.py

Django

unread,
Nov 30, 2017, 5:56:03 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+--------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Description changed by Hrishikesh Barman:

Old description:

> When subclassing test cases, decorated tags are inherited ONLY when the
> subclass does not provide its own tag decorator. If the subclass provides
> its own decorator(s) then the parent's tags are ignored.
>
> If you use the attached file, running:
>
> {{{
> python manage.py test
> }}}
>
> yields two test cases as expected. However, running
>
> {{{
> python manage.py test tag=foo-tests
> }}}
>
> OR
>
> {{{
> python manage.py test tag=baz-tests
> }}}
>
> Will each only run one test a piece. I would expect that the former would
> run both test cases, given all of the test cases in the attached file are
> inherited from a class which is decorated with that tag.

New description:

When subclassing test cases, decorated tags are inherited ONLY when the
subclass does not provide its own tag decorator. If the subclass provides
its own decorator(s) then the parent's tags are ignored.

If you use the attached file, running:

{{{
python manage.py test
}}}

yields two test cases as expected. However, running

{{{
python manage.py test --tag=foo-tests
}}}

OR

{{{
python manage.py test --tag=baz-tests
}}}

Will each only run one test a piece. I would expect that the former would
run both test cases, given all of the test cases in the attached file are
inherited from a class which is decorated with that tag.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:1>

Django

unread,
Nov 30, 2017, 6:11:14 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+--------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by Hrishikesh Barman):

Replying to [ticket:28869 William Ayd]:


> When subclassing test cases, decorated tags are inherited ONLY when the
subclass does not provide its own tag decorator. If the subclass provides
its own decorator(s) then the parent's tags are ignored.

> Will each only run one test a piece. I would expect that the former
would run both test cases, given all of the test cases in the attached
file are inherited from a class which is decorated with that tag.

I am a new contributor, I might be completely wrong but I think this is
how the `tag` decorator is supposed to work. When a parameter is
explitcitly passed into the tag decorator, the function should use that
tag and if the need is to specify another tag it should be done by
separating by commas.

{{{
@tag('slow', 'core')
def test_slow_but_core(self):
pass
}}}

docs: https://docs.djangoproject.com/en/1.11/topics/testing/tools
/#tagging-tests

If this is a confirmed bug, I'd like to work on it if you let me. :)

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:2>

Django

unread,
Nov 30, 2017, 6:14:36 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+--------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Hrishikesh Barman):

* cc: Hrishikesh Barman (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:3>

Django

unread,
Nov 30, 2017, 9:45:20 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+--------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by William Ayd):

Hi Hrishikesh,

My point was that it's strange that FooBar inherits the tag from it's
parent while FooBaz does not, simply because the latter adds another tag
of its own. Either neither class should inherit the tag from its parent,
or both of them should (I think both inheriting would be preferred).

From what I see this can be easily fixed changing the tag function in
Django.tests.util from:

{{{
def tag(*tags):
"""
Decorator to add tags to a test class or method.
"""
def decorator(obj):
setattr(obj, 'tags', set(tags))
return obj
return decorator
}}}

To

{{{
def tag(*tags):
"""
Decorator to add tags to a test class or method.
"""
def decorator(obj):
if hasattr(obj, 'tags'):
obj.tags = obj.tags | set(tags)
else:
setattr(obj, 'tags', set(tags))
return obj
return decorator
}}}

So that subclasses can inherit any existing tags from their parents

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:4>

Django

unread,
Nov 30, 2017, 11:59:59 PM11/30/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+------------------------------------

Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


Comment:

The proposed fix looks appropriate.

Please submit a PR with your proposed patch and a regression test in
[https://github.com/django/django/blob/master/tests/test_runner/test_discover_runner.py
tests/test_runner/test_discover_runner.py] based on the structure
introduced by d4dc775620fc57e962165eab98a77264e3dd16b2.

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:5>

Django

unread,
Dec 1, 2017, 2:36:35 AM12/1/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+------------------------------------
Reporter: William Ayd | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Hrishikesh Barman):

Hello William,

I understand it now. thanks. :)

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:6>

Django

unread,
Dec 1, 2017, 11:02:24 AM12/1/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+---------------------------------------
Reporter: William Ayd | Owner: William Ayd
Type: Bug | Status: assigned

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by William Ayd):

* owner: nobody => William Ayd
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:7>

Django

unread,
Dec 1, 2017, 11:04:05 AM12/1/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-----------------------------------+---------------------------------------
Reporter: William Ayd | Owner: William Ayd
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by William Ayd):

* has_patch: 0 => 1


Comment:

Please note that I have fixed this and included regression tests in branch
ticket_28869 available in my GitHub repo

[https://github.com/WillAyd/django/tree/ticket_28869]

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:8>

Django

unread,
Dec 16, 2017, 5:59:13 PM12/16/17
to django-...@googlegroups.com
#28869: Django.test.tag Inconsistent Inheritance
-------------------------------------+-------------------------------------
Reporter: William Ayd | Owner: William
| Ayd
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Martin):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:9>

Django

unread,
Dec 29, 2017, 2:33:45 PM12/29/17
to django-...@googlegroups.com
#28869: Make test tags inherit from the class rather than be overridden by tags on
the method
-----------------------------------+---------------------------------------

Reporter: William Ayd | Owner: William Ayd
Type: Bug | Status: assigned
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


Comment:

I left comments for improvement on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:10>

Django

unread,
Jan 8, 2018, 9:34:40 PM1/8/18
to django-...@googlegroups.com
#28869: Make test tags inherit from the class rather than be overridden by tags on
the method
-----------------------------------+---------------------------------------
Reporter: William Ayd | Owner: William Ayd
Type: Bug | Status: closed

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: testing, tag | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+---------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"09530e61a0035192ca8bcdebc5ead13d14c16eb0" 09530e61]:
{{{
#!CommitTicketReference repository=""
revision="09530e61a0035192ca8bcdebc5ead13d14c16eb0"
Fixed #28869 -- Made tagged test classes and methods inherit tags from
parents.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28869#comment:11>

Reply all
Reply to author
Forward
0 new messages