You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed with @fcanobrash, I'm only opening this here so we can keep track if it.
The AUTOUNIT_DONT_TEST_OUTPUT_FIELDS setting cannot be used to ignore fields that are not in the first level of items. We thought about using jmespath but that doesn't provide a way to modify data, only access it. My current workaround for this is the following monkeypatch:
importoperatorfromcontextlibimportsuppressfromfunctoolsimportreduceimportscrapy_autounitfromscrapy_autounit.cassetteimportCassettefromscrapy_autounit.playerimportPlayerclassIgnoreNestedFieldsPlayer(Player):
"""Patched player that allows to specify nested fields to be ignored. """@classmethoddeffrom_fixture(cls, path):
"""This override is only needed while https://github.com/scrapinghub/scrapy-autounit/pull/88 is not merged"""cassette=Cassette.from_fixture(path)
returncls(cassette)
def_filter_output_fields(self, item):
dont_test=self.spider.settings.get("AUTOUNIT_DONT_TEST_OUTPUT_FIELDS", [])
ifnotdont_test:
dont_test=self.spider.settings.get("AUTOUNIT_SKIPPED_FIELDS", [])
forentryindont_test:
*first_keys, last_key=entry.split(".")
iffirst_keys:
withsuppress(KeyError):
item=reduce(operator.getitem, first_keys, item)
item.pop(last_key, None)
scrapy_autounit.player.Player=IgnoreNestedFieldsPlayer
After this I'm able to do the following in settings.py:
As discussed with @fcanobrash, I'm only opening this here so we can keep track if it.
The
AUTOUNIT_DONT_TEST_OUTPUT_FIELDS
setting cannot be used to ignore fields that are not in the first level of items. We thought about usingjmespath
but that doesn't provide a way to modify data, only access it. My current workaround for this is the following monkeypatch:After this I'm able to do the following in settings.py:
The text was updated successfully, but these errors were encountered: