[Django] #28361: One of the tutorial test cases fail on certain systems

58 views
Skip to first unread message

Django

unread,
Jul 5, 2017, 2:58:32 AM7/5/17
to django-...@googlegroups.com
#28361: One of the tutorial test cases fail on certain systems
-----------------------------------------+-------------------------------
Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Keywords: datetime test
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+-------------------------------
On my Windows machine the test
`test_was_published_recently_with_old_question` fails. I'm fairly sure I
copied every piece of code correctly, but even on a theoretical level I'm
not sure why it would succeed.

{{{
>python manage.py test polls
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
......F.
======================================================================
FAIL: test_was_published_recently_with_old_question
(polls.tests.QuestionModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "[...]\polls\tests.py", line 81
, in test_was_published_recently_with_old_question
self.assertIs(old_question.was_published_recently(), False)
AssertionError: True is not False

----------------------------------------------------------------------
Ran 8 tests in 0.031s

FAILED (failures=1)
Destroying test database for alias 'default'...
}}}

The test case in question:

{{{
time = timezone.now() - datetime.timedelta(days=1)
old_question = Question(pub_date=time)
self.assertIs(old_question.was_published_recently(), False)
}}}

The check used in the function is `now - datetime.timedelta(days=1) <=
self.pub_date <= now`, and the test sets the `pub_date` to exactly one day
before now. Can we be sure that time passes between creating the `time`
variable and checking it against the question's `pub_date`? This certainly
doesn't seem to be the case on my machine (hence the fail).

I think a good and unambiguous solution would be to set `time` to 1 day
and 1 second in the past. This still test the edge case, but it is
guaranteed that the check will succeed, even with `<=`.

I'm not quite sure what the difference is, but an interesting comparison
is how python handles the following on this machine:

{{{
>>> datetime.now(), datetime.now(), datetime.now(), datetime.now(),
datetime.now(), datetime.now()
(datetime.datetime(2017, 7, 4, 17, 28, 20, 132149),
datetime.datetime(2017, 7, 4, 17, 28, 20, 132149), datetime.datetime(2017,
7, 4, 17, 28, 20, 132149), datetime.datetime(2017, 7, 4, 17, 28, 20,
132149), datetime.datetime(2017, 7, 4, 17, 28, 20, 132149),
datetime.datetime(2017, 7, 4, 17, 28, 20, 132149))
}}}

Whereas on my Linux machine every instance has a different value.

System specs:
Windows 8.1 (Version 6.3, Build 9600)
Python 3.6.1
Django 1.11.3

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

Django

unread,
Jul 5, 2017, 3:01:54 AM7/5/17
to django-...@googlegroups.com
#28361: One of the tutorial test cases fails on certain systems
-------------------------------+--------------------------------------

Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:

Keywords: datetime test | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------

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

Django

unread,
Jul 5, 2017, 7:50:13 AM7/5/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------

Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Ready for checkin


Comment:

When merging 268a646353c6fa9e5fc3730e13b386ddabb018ef, I thought this
could be a problem.

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

Django

unread,
Jul 5, 2017, 10:02:59 AM7/5/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by benjaoming):

@martonbognar - what happens if you run:


{{{
while True:
datetime.now()
}}}

How often does it change? Might reveal some kind of precision level of
said Windows system.

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

Django

unread,
Jul 5, 2017, 10:22:07 AM7/5/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by marton bognar):

Replying to [comment:3 benjaoming]:


> @martonbognar - what happens if you run:
>
>
> {{{
> while True:
> datetime.now()
> }}}
>
> How often does it change? Might reveal some kind of precision level of
said Windows system.

Here's an excerpt of the output:
https://gist.github.com/martonbognar/4de49f322573fc162c1594efd24efe8c
It does not seem very deterministic to me.

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

Django

unread,
Jul 5, 2017, 10:25:44 AM7/5/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by marton bognar):

Replying to [comment:2 Tim Graham]:


> When merging 268a646353c6fa9e5fc3730e13b386ddabb018ef, I thought this
could be a problem.

So what's the next step? Sorry, I'm new to django issue tracking, should I
create a pull request with my proposed changes or will someone more
qualified take care of the ticket?

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

Django

unread,
Jul 5, 2017, 11:27:39 AM7/5/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

You may create a pull request.

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

Django

unread,
Jul 6, 2017, 3:30:22 PM7/6/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: marton
| bognar
Type: Bug | Status: assigned
Component: Documentation | Version: 1.11
Severity: Normal | Resolution:
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by marton bognar):

* owner: nobody => marton bognar
* status: new => assigned


Comment:

Thanks, I submitted a pull request, hope it is alright:
https://github.com/django/django/pull/8711

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

Django

unread,
Jul 6, 2017, 6:24:06 PM7/6/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: marton
| bognar
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"82741605206382d0afd879c4bce174ef3d6e8aea" 82741605]:
{{{
#!CommitTicketReference repository=""
revision="82741605206382d0afd879c4bce174ef3d6e8aea"
Fixed #28361 -- Fixed possible time-related failure in
was_published_recently() tutorial test.

Regression in 268a646353c6fa9e5fc3730e13b386ddabb018ef.
}}}

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

Django

unread,
Jul 6, 2017, 6:24:18 PM7/6/17
to django-...@googlegroups.com
#28361: test_was_published_recently_with_old_question test in the tutorial is time
dependent
-------------------------------------+-------------------------------------
Reporter: marton bognar | Owner: marton
| bognar
Type: Bug | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: datetime test | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"5b450b84e14f42302f58ec1f15a67a368e64d85c" 5b450b8]:
{{{
#!CommitTicketReference repository=""
revision="5b450b84e14f42302f58ec1f15a67a368e64d85c"
[1.11.x] Fixed #28361 -- Fixed possible time-related failure in
was_published_recently() tutorial test.

Regression in 268a646353c6fa9e5fc3730e13b386ddabb018ef.

Backport of 82741605206382d0afd879c4bce174ef3d6e8aea from master
}}}

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

Reply all
Reply to author
Forward
0 new messages