TrackrefTestCase.test_get_oldest: protect from lack of precision

This commit is contained in:
Adrián Chaves 2020-07-03 01:41:47 +02:00
parent 3199048520
commit eb93774256
1 changed files with 14 additions and 0 deletions

View File

@ -1,7 +1,10 @@
import unittest
from io import StringIO
from time import sleep, time
from unittest import mock
from twisted.trial.unittest import SkipTest
from scrapy.utils import trackref
@ -55,7 +58,18 @@ Foo 1 oldest: 0s ago\n\n''')
def test_get_oldest(self):
o1 = Foo() # NOQA
o1_time = time()
o2 = Bar() # NOQA
o3_time = time()
if o3_time <= o1_time:
sleep(0.01)
o3_time = time()
if o3_time <= o1_time:
raise SkipTest('time.time is not precise enough')
o3 = Foo() # NOQA
self.assertIs(trackref.get_oldest('Foo'), o1)
self.assertIs(trackref.get_oldest('Bar'), o2)