Skip to content

Crash in one test when switching to pytest #150

Description

@vinitkumar

Recently decided to use pytest fully and discovered this failure in test.

=================================== FAILURES ===================================
[52](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:53)
__________________ TestDict2xml.test_dict2xml_str_list_header __________________
[53](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:54)
[54](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:55)
self = <tests.test_dict2xml.TestDict2xml object at 0x7f687bd951d0>
[55](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:56)
[56](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:57)
    def test_dict2xml_str_list_header(self):
[57](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:58)
        from json2xml.dicttoxml import dict2xml_str
[58](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:59)
        item_func = dicttoxml.default_item_func
[59](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:60)
        item = {'frame_color': 'red'}
[60](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:61)
        parent = 'Bike'
[61](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:62)
        xml_str = dict2xml_str(attr_type=False, attr={}, item=item, item_func=item_func,
[62](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:63)
                               cdata=False, item_name='item', item_wrap=False, parentIsList=True,
[63](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:64)
                               parent=parent, list_headers=True)
[64](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:65)
[65](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:66)
>       assert f'{"<Bike><frame_color>red</frame_color></Bike>"}' == xml_str
[66](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:67)
E       assert '<Bike><frame...color></Bike>' == '<Bike><frame...color></Bike>'
[67](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:68)
E         - <Bike><frame_color id="item_464503">red</frame_color></Bike>
[68](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:69)
E         ?                   -----------------
[69](https://github.com/vinitkumar/json2xml/runs/7473036610?check_suite_focus=true#step:5:70)
E         + <Bike><frame_color>red</frame_color></Bike>

Which doesn't happen when the test is run isolated. It means one of the other tests is affecting this particular tests.

Curious about this, I commented most of the tests except test_get_unique_id
and voilà, it does cause this test to fail.

On a closer look, it does seem that we are using a global IDs list that gets mutated and shared across these two tests.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions