https://github.com/nvbn/pytest-docker-pexpect
pytest plugin for writing functional tests with pexpect and docker
https://github.com/nvbn/pytest-docker-pexpect
Last synced: 20 days ago
JSON representation
pytest plugin for writing functional tests with pexpect and docker
- Host: GitHub
- URL: https://github.com/nvbn/pytest-docker-pexpect
- Owner: nvbn
- Created: 2015-09-02T15:36:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-14T23:42:34.000Z (over 6 years ago)
- Last Synced: 2025-03-26T14:17:50.249Z (27 days ago)
- Language: Python
- Size: 13.7 KB
- Stars: 30
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pytest-docker-pexpect [](https://travis-ci.org/nvbn/pytest-docker-pexpect)
py.test plugin for writing simple functional tests with pexpect and docker.
## Installation
```python
pip install pytest-docker-pexpect
```## Usage
The plugin provides `spawnu` fixture, that could be called like
`spawnu(tag, dockerfile_content, command)`, it returns `pexpect.spwanu` attached to `command`
runned inside a container that built with `tag` and `dockerfile`:```python
def test_echo(spawnu):
proc = spawnu(u'ubuntu', u'FROM ubuntu:latest', u'bash')
proc.sendline(u'ls')
```Current working directory available inside the container in `/src`.
It's also possible to pass arguments to `docker run` with `spawnu`:
```python
spawnu(u'ubuntu', u'FROM ubuntu:latest', u'bash',
docker_run_arguments=[u'--expose', u'80'])
````spawnu` provides [pexpect API](https://pexpect.readthedocs.io/en/stable/api/pexpect.html#spawn-class)
and additional docker-specific API:* `proc.docker_container_id` – container id
* `proc.docker_inspect()` – decoded json output of `docker inspect`
* `proc.docker_stats()` – decoded json output of `docker stats`Also the plugin provides `TIMEOUT` fixture, that can be used for simple asserts, like:
```python
assert proc.expect([TIMEOUT, u'1'])
````run_without_docker` fixtures, that indicates that docker isn't used.
If you want to disable tests if docker isn't available, use `@pytest.mark.skip_without_docker`.
If you want to run parametrized test only once without docker, use
`@pytest.mark.once_without_docker`.## Usage without docker
With flag `--run-without-docker` tests can be run in environment without docker.
In this mode tests runs only for first container and docker initialization steps are skipped.
Be careful, in this mode all commands will be execute directly on local system!## Licensed under MIT