sanic: Random Failures during tox run on Mac
Describe the bug When running Unit Test in local machine (mac), few test cases randomly fail and re-cover during re-run.
Error Output
# Test session starts (platform: darwin, Python 3.5.6, pytest 3.3.2, pytest-sugar 0.9.1)
def test_default_server_error_request_timeout():
client = DelayableSanicTestClient(request_timeout_default_app, None, 3)
request, response = client.get('/1')
> assert response.status == 408
E assert 200 == 408
E + where 200 = <test_request_timeout.DelayableTCPConnector.RequestContextManager object at 0x10723ccf8>.status
tests/test_request_timeout.py:194: AssertionError
# Test session starts (platform: darwin, Python 3.7.0, pytest 3.3.2, pytest-sugar 0.9.1)
def test_default_server_error_request_timeout():
client = DelayableSanicTestClient(request_timeout_default_app, None, 3)
request, response = client.get('/1')
> assert response.status == 408
E assert 200 == 408
E + where 200 = <test_request_timeout.DelayableTCPConnector.RequestContextManager object at 0x112d87470>.status
tests/test_request_timeout.py:194: AssertionError
# py37-no-ext develop-inst-nodeps: <path>
# py37-no-ext installed: aiofiles==0.4.0,aiohttp==3.2.1,async-generator==1.10,async-timeout==3.0.1,attrs==18.2.0,beautifulsoup4==4.6.3,chardet==2.3.0,coverage==4.5.1,gunicorn==19.9.0,httptools==0.0.11,idna==2.7,multidict==4.4.2,pluggy==0.6.0,py==1.7.0,pytest==3.3.2,pytest-cov==2.6.0,pytest-sanic==0.1.13,pytest-sugar==0.9.1,-e git+git@github.com:harshanarayana/sanic.git@e3a27c2cc485d57aa1ff87d9f69098e4ab12727e#egg=sanic,six==1.11.0,termcolor==1.1.0,websockets==6.0,yarl==1.2.6
# py37-no-ext run-test-pre: PYTHONHASHSEED='27345397'
# py37-no-ext runtests: commands[0] | pytest tests --cov sanic --cov-report=
# Test session starts (platform: darwin, Python 3.7.0, pytest 3.3.2, pytest-sugar 0.9.1)E AssertionError: assert {'Connection'...p-Alive': '2'} == {'Connection':...p-Alive': '2'}
E Omitting 3 identical items, use -vv to show
E Differing items:
E {'Content-Length': '12'} != {'Content-Length': '11'}
Code snippet NA
Expected behavior Existing Unit Tests to pass in all Virtual env during tox execution.
Environment (please complete the following information):
- OS: macOS Mojave
- Version 10.14 (18A391)
Additional context NA
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 43 (43 by maintainers)
I finally found the problem 😓
Even the full test is now reporting “correctly” (prior to PR #1403):
How? Dead simple. The problem is here. When installing
pytest-sanicas a test dependency, it will try to install what? Sanic. For some reason, under Python 3.5, theSANIC_NO_UVLOOPandSANIC_NO_UJSONenvironment variables aren’t broadcast whentoxinstallspytest-sanic… So it ends up requiring Sanic, which requires and installsuvloopandujson😒This is way too random. Maybe because
pytest-sanichas Python 3.5 inside its setup classifiers? I don’t really know 😕I tried to set
passenvinsidetox.ini, set withSANIC_NO_UJSONandSANIC_NO_UVLOOP, with no luck as well:Anyway, here’s
pip freezeunder thetoxenvironment withpytest-sanicintox.ini(as it is today):And here’s
pip freezeunder thetoxenvironment withoutpytest-sanic(that’s not even used in testing afaik):That was a needle in a hay.
@yunstanford should we just remove
pytest-sanicas a test dependency from Tox? IMHO it creates a circular dependency as well …@vltr when in doubt… blame it on the gremlins.
@vltr
Looks so good 😀
I confirm the reports from @harshanarayana regarding
py37-no-ext.The problem is: under
ujson, an objectdumpsdoesn’t create a space between colons:, while the Pythonjsonmodule does it (and after commas,too):To fix that, you just need to tell the
jsonmodule to not add these spaces after colons:I think a minor PR should fix that in responses.py using
functools.partial😉, basically:@vltr I can confirm that these random intermittent errors are seen no more. We can close this issue (The original issue I reported are all sorted). Thanks, everyone for the help 😃
@yunstanford , thanks for “fixing” pytest-sanic regarding this issue. I’ll bring up the matter for bringing some Sanic related projects (that are really a plus to have, like yours) into the
huge-successumbrella 😉@yunstanford great, we can sleep on that and think about proposals for the future 😉
@yunstanford I know
pytest-sanicis not a direct dependency of Sanic, but it’s part of the development process (as being a test dependency). If Sanictest_clientis error prone, then we should make it work or changepytest-sanicso it’ll act as an utility tool (without explicitly requiring Sanic). Otherwise, we will not be able to guarantee our testing environments, and that’s a big problem.Since we are talking about this, why not bring
pytest-sanicunder thehuge-success“umbrella”?@vltr If we remove
sanicas a dependency frompytest-sanicunder it’sinstall_requires,pytest-sanicwill not bother aboutsanicduring the installation. That should address the circular dependency issue you were talking about before.So, now that we are only going to use the
sanicwe have in our cloned repo for everything, if the right env variables forSANIC_NO_UJSONandSANIC_NO_UVLOOPgets passed intotoxthat should fix our main problem.@harshanarayana don’t worry, I already addressed the issue with the core-devs to find the best solution - IMO
pytest-sanicshould not be a dependency in Sanic in any way, but let’s see what we can come out with.@vltr Please do let me know if there is anything I can do to help your investigation into this criminal matter. 😉
@harshanarayana somehow, if I execute only the
-no-exttests,uvloopandujsonend up being installed into the Python 3.5 environment (throughtox). No matter what (and how) I call [tox],ujsonanduvloopwill be in that environment. I’m digging a little bit deeper now into what happens withtoxand the environment variables set to not install these dependencies being ignored in Python 3.5.@vltr Creating a PR with modified Test cases in a while. Saved me the effort of debugging the issue. 😃
This happens on my system too, exactly the same error - and I use Arch Linux, so it’s not an OS problem 😒