pytest-sugar
pytest-sugar copied to clipboard
docker+venv, stdout is not printed per test before running test
When reporting an issue, include a way to reproduce the bug. For example:
Command used to run py.test
py.test
(with configuration) pytest.ini
[pytest]
addopts = --full-trace --verbose --force-sugar
Environment
docker + pipenv
it runs in a docker (based off python:slim), then enters the pipenv virtual environment
docker run <stuff>
"export PIPENV_SKIP_LOCK=true; \
pipenv install --dev; echo; \
pipenv shell"
Launching subshell in virtual environment…
root@d65b03da3615:/app# . /root/.local/share/virtualenvs/app-4PlAip0Q/bin/activate
# cat /etc/issue
Debian GNU/Linux 9 \n \l
# uname -a
Linux d65b03da3615 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64 GNU/Linux
# pipenv --version
pipenv, version 2018.11.26
Test file
We have a PoC SLOW test, which makes this "more obvious". (admittedly bad practice, this will be fixed later - but it has highlighted this issue w/ sugar in our environment)
def test_all():
for test in tests
for thing in matrix
# do things
assert ()...
Output
(app) root@d65b03da3615:/app# py.test
Test session starts (platform: linux, Python 3.7.3, pytest 4.5.0, pytest-sugar 0.9.2)
cachedir: .pytest_cache
rootdir: /app, inifile: pytest.ini
plugins: sugar-0.9.2, cov-2.7.1
collecting ...
<<<HANGS HERE>>> (takes about 20sec+ to show the next line)
tests/integration/a_slow_test.py::test_all ✓ 100% ██████████
<<<suddenly then it prints the test ^^^, 100% done>>>
Results (21.00s):
1 passed
-- So, the issue is of course, that sugar seems to NOT be printing the progress at all until the test is DONE (which makes the entire point of sugar moot and not useful).
COMPARE, without sugar:
(app) root@d65b03da3615:/app# py.test -p no:sugar
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.7.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0 -- /root/.local/share/virtualenvs/app-4PlAip0Q/bin/python
cachedir: .pytest_cache
rootdir: /app, inifile: pytest.ini
plugins: cov-2.7.1
collected 1 item
tests/integration/a_slow_test.py::test_all <<SLOW_HERE>> -> PASSED [100%]
============================================================================================ 1 passed in 20.84 seconds ============================================================================================
Without sugar, we at least get the CURRENT test being run, then dumps PASSED + 100%.
PS: i just noticed the pytest-xdist note on the main page, tried with that just now, same issue persists
(app) root@d65b03da3615:/app# py.test
Test session starts (platform: linux, Python 3.7.3, pytest 4.5.0, pytest-sugar 0.9.2)
cachedir: .pytest_cache
rootdir: /app, inifile: pytest.ini
plugins: xdist-1.28.0, sugar-0.9.2, forked-1.0.2, cov-2.7.1
collecting ...
<<<HANGS while running the first test>>>
tests/integration/a_slow_test.py::test_all ✓ 100% ██████████
Results (21.30s):
1 passed
I'm also running into this issue. I'm running an app in one container, and running pytest in another (there are reasons) and I just get the final output once the tests are completed and nothing streamed out.
PYTHONUNBUFFERED?
Or do you mean just the fact that nothing gets displayed before test is ran (i.e. is this related to Docker)?