mirror of https://github.com/scrapy/scrapy.git
Use the spider class import path as name if no name is specified otherwise
This commit is contained in:
parent
6a1e7f2f11
commit
5a596a8620
|
|
@ -12,6 +12,7 @@ from twisted.internet.defer import Deferred
|
|||
|
||||
from scrapy import signals
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.utils.python import global_object_name
|
||||
from scrapy.utils.trackref import object_ref
|
||||
from scrapy.utils.url import url_is_from_spider
|
||||
|
||||
|
|
@ -52,6 +53,8 @@ class Spider(object_ref):
|
|||
def __init__(self, name: Optional[str] = None, **kwargs: Any):
|
||||
if name is not None:
|
||||
self.name = name
|
||||
elif not getattr(self, "name", None):
|
||||
self.name = global_object_name(self.__class__)
|
||||
self.__dict__.update(kwargs)
|
||||
if not hasattr(self, "start_urls"):
|
||||
self.start_urls: List[str] = []
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from scrapy.spiders import (
|
|||
XMLFeedSpider,
|
||||
)
|
||||
from scrapy.spiders.init import InitSpider
|
||||
from scrapy.utils.python import global_object_name
|
||||
from scrapy.utils.test import get_crawler
|
||||
from tests import get_testdata
|
||||
|
||||
|
|
@ -54,8 +55,9 @@ class SpiderTest(unittest.TestCase):
|
|||
self.assertEqual(spider.foo, "bar")
|
||||
|
||||
def test_spider_without_name(self):
|
||||
self.assertFalse(hasattr(self.spider_class, "name"))
|
||||
spider = self.spider_class()
|
||||
self.assertFalse(hasattr(spider, "name"))
|
||||
self.assertEqual(spider.name, global_object_name(self.spider_class))
|
||||
|
||||
def test_from_crawler_crawler_and_settings_population(self):
|
||||
crawler = get_crawler()
|
||||
|
|
|
|||
Loading…
Reference in New Issue