Skip to content

Commit

Permalink
Attempt to fix flaky test on Python 2
Browse files Browse the repository at this point in the history
This test sometimes fails on AppVeyor with:

```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <listiterator object at 0x0549DC50>
    leaked_types = sum(1 for _ in gc.garbage
>                   if 'PseudoFixtureDef' in str(_))
E   UnicodeEncodeError: 'ascii' codec can't encode character u'\u263a' in position 23: ordinal not in range(128)
test_request_garbage.py:19: UnicodeEncodeError
====================== 1 passed, 1 error in 1.39 seconds ======================
```

Use our internal "safe_repr" function to handle Encode errors: who knows
what objects are in garbage after all.
  • Loading branch information
nicoddemus committed May 4, 2018
1 parent 27651f4 commit fa76a5c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ def test_request_garbage(self, testdir):
testdir.makepyfile("""
import sys
import pytest
from _pytest.compat import safe_str
import gc
@pytest.fixture(autouse=True)
Expand All @@ -539,7 +540,7 @@ def something(request):
gc.collect()
leaked_types = sum(1 for _ in gc.garbage
if 'PseudoFixtureDef' in str(_))
if 'PseudoFixtureDef' in safe_str(_))
gc.garbage[:] = []
Expand Down

0 comments on commit fa76a5c

Please sign in to comment.