TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

Bgarcial

다음과 같은 기능이 있습니다.

def checking_remote_local_groups(data: List[dict], groups: List[dict]) -> List[dict]:
    step = 'GET_GROUPS_TO_CHECK'
    groups_to_check = []
    local_groups = [x['group'] for x in data]

    # Using set to get differences between local and AAD groups
    local_groups_set = set(local_groups)
   
    groups_set = set(x['name'] for x in groups)
    # If local AAD groups set are not in AAD groups, raise an Error on the workflow.
    if local_groups_set - groups_set:
        # SyncException is implemented somewhere.
        raise SyncException(
            f'{local_groups_set - groups_set} local group is not an AAD group\nCreate it via speckle-infra terraform',
            "We need to get in line, local and AAD groups. Additional {} group received from users.yaml".format(
                local_groups_set - groups_set
            ),
            step
        )
    # If remote groups set are not in local groups 
    if groups_set - local_groups_set:
        # Just notify it to the user
        warnings.warn(
            f"""
            {groups_set - local_groups_set} AAD group is not on users.yml as a local group
            Please add it if needed
            """
            )
    # If remote groups are the same than local groups
    elif local_groups_set == groups_set:
        print("AAD and local groups are inline"
            )
    return groups_to_check

이 경우 경고를 트리거하기 때문에 assertWarns 어설 션을 사용하여 단위 테스트를 수행 하여 두 번째 if섹션 코드 ( If remote groups set are not in local groups ) 의 동작을 확인하고 싶습니다 . 그래서 나는 가지고있다:

class MyTestCase(unittest.TestCase):

    def test_warning_checking_remote_group_not_in_local_groups(self):
        # local groups
        data = [{'group': 'foobar'}, {'group': 'test'}]
        
        # remote groups
        groups = [{'name': 'foobar'}, {'name': 'test'}, {'name': 'missing'}]
        self.assertWarns(
            UserWarning,
            checking_aad_local_groups(data, groups),
            [{"name": "missing"}]
        )

이 출력을 얻었습니다.

test_sync.py .F...........                                               [100%]

=================================== FAILURES ===================================
______ GroupsTestCase.test_warning_checking_aad_group_not_in_local_groups ______

self = <test_sync.GroupsTestCase testMethod=test_warning_checking_remote_group_not_in_local_groups>

    def test_warning_checking_remote_group_not_in_local_groups(self):
        data = [{'group': 'foobar'}, {'group': 'test'}]
        groups = [{'name': 'foobar'}, {'name': 'test'}, {'name': 'missing'}]
>       self.assertWarns(
            UserWarning,
            checking_aad_local_groups(data, groups),
            [{"name": "missing"}]
        )
E       TypeError: 'list' object is not callable

test_sync.py:158: TypeError
=============================== warnings summary ===============================
test_sync.py::GroupsTestCase::test_warning_checking_aad_group_not_in_local_groups
  /home/runner/work/speckle-user-management/speckle-user-management/groups.py:31: UserWarning: 
              *********************** WARNING ... ***********************
              {'missing'} AAD group is not on users.yml as a local group
              Please add it if needed
              *********************** WARNING ... ***********************
              
    warnings.warn(

-- Docs: docs.pytest.org/en/latest/warnings.html
=========================== short test summary info ============================
FAILED test_sync.py::GroupsTestCase::test_warning_checking_remote_group_not_in_local_groups

매개 변수로 보내는 사전 목록이 허용되지 않거나 assertWarns()예상 되는 데이터 유형에 사용할 수 없다는 것을 이해합니다 .

그럼에도 불구하고 예상했던 메시지 ( {'missing'} AAD group is not on users.yml as a local group, Please add it if needed)가 표시되지만이 테스트 통과에서 기대합니다.

어떻게 사용하는 가장 좋은 방법입니다 assertWarns().

assertFalse를 사용하면 테스트를 통과했지만 사용할 수있는 가장 구체적인 / 더 나은 주장인지 확실하지 않습니다.

약탈자

당신이 호출 할 때 assertWarns(UserWarning, checking_aad_local_groups(...))당신은 호출 checking_aad_local_groups하고 그 결과를 전달합니다 assertWarns. assertWarns경고 감지 코드에서 래핑 할 수 있도록 콜 러블 을 제공하려고합니다 .

self.assertWarns(UserWarning, checking_aad_local_groups, (data, groups))

또는 컨텍스트 관리자로 사용할 수 있습니다.

with self.assertWarns() as w:
   checking_aad_local_groups(data, groups)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다. 최대 쌍 단위 제품

분류에서Dev

zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

분류에서Dev

firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

분류에서Dev

Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Post'개체를 호출 할 수 없습니다.

분류에서Dev

groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

분류에서Dev

Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '게임'개체를 호출 할 수 없습니다.

분류에서Dev

Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Python-TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Weather'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

분류에서Dev

Python TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

분류에서Dev

Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

분류에서Dev

Python 프로그램 오류 '목록'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

분류에서Dev

TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

분류에서Dev

'모듈'개체의 TypeError는 호출 할 수 없습니다.

Related 관련 기사

  1. 1

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  2. 2

    TypeError : '목록'개체를 호출 할 수 없습니다. 최대 쌍 단위 제품

  3. 3

    zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

  4. 4

    TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

  5. 5

    TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

  6. 6

    TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

  7. 7

    firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

  8. 8

    Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

  9. 9

    TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

  10. 10

    TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

  11. 11

    TypeError : 'Post'개체를 호출 할 수 없습니다.

  12. 12

    groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

  13. 13

    Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

  14. 14

    Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

  15. 15

    TypeError : '게임'개체를 호출 할 수 없습니다.

  16. 16

    Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

  17. 17

    Python-TypeError : 'list'개체를 호출 할 수 없습니다.

  18. 18

    TypeError : 'Weather'개체를 호출 할 수 없습니다.

  19. 19

    TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

  20. 20

    Python TypeError : '모듈'개체를 호출 할 수 없습니다.

  21. 21

    TypeError '모듈'개체를 호출 할 수 없습니다.

  22. 22

    django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

  23. 23

    Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

  24. 24

    TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

  25. 25

    Python 프로그램 오류 '목록'개체를 호출 할 수 없습니다.

  26. 26

    TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

  27. 27

    TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

  28. 28

    TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

  29. 29

    '모듈'개체의 TypeError는 호출 할 수 없습니다.

뜨겁다태그

보관