Skip to content

Instantly share code, notes, and snippets.

@davidemoro
Created February 12, 2019 22:51
Show Gist options
  • Save davidemoro/2e376aac92901589ead815d46add7c10 to your computer and use it in GitHub Desktop.
Save davidemoro/2e376aac92901589ead815d46add7c10 to your computer and use it in GitHub Desktop.
websocketd test with pytest-play using YAML files
#!/bin/bash
while read line
do
echo "$line"
done
$ docker run --rm -it -v $(pwd):/src --network host davidemoro/pytest-play --variables variables.yml
========================================================= test session starts =========================================================
platform linux -- Python 3.6.8, pytest-3.10.1, py-1.7.0, pluggy-0.8.1
rootdir: /src, inifile:
plugins: variables-1.7.1, splinter-2.0.0, pypom-navigation-2.0.2, play-2.0.1
collected 2 items
test_websocket.yml .. [100%]
========================================================== warnings summary ===========================================================
test_websocket.yml::test_websocket.yml0
/usr/local/lib/python3.6/site-packages/_pytest/fixtures.py:828: RemovedInPytest4Warning: Fixture "tmpdir" called directly. Fixtures are not meant to be called directly, are created automatically when test functions request them as parameters. See https://docs.pytest.org/en/latest/fixture.html for more information.
res = fixturefunc(**kwargs)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================ 2 passed, 1 warnings in 2.38 seconds =================================================
#!/bin/bash
docker run --rm -it -v $(pwd):/src --network host davidemoro/pytest-play --variables variables.yml
#!/bin/bash
./websocketd --port=8081 ./echo_ws.sh
test_data:
- data: hello
- data: world
---
- comment: connect to websocket url
provider: play_websocket
type: connect
options:
url: "$websocket_url"
timeout: 5
- comment: send some data to websocket server
provider: play_websocket
type: send
url: "$websocket_url"
payload: $data
- comment: receive response (echo)
provider: play_websocket
type: recv
url: "$websocket_url"
variable: data
variable_expression: results
assertion: variables['data'] == '$data'
---
pytest-play:
websocket_url: ws://0.0.0.0:8081/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment