Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker+venv, stdout is not printed per test before running test #174

Open
mcallaghan-bsm opened this issue May 16, 2019 · 4 comments
Open
Labels

Comments

@mcallaghan-bsm
Copy link

mcallaghan-bsm commented May 16, 2019

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%.

@mcallaghan-bsm
Copy link
Author

mcallaghan-bsm commented May 17, 2019

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

@mcallaghan-bsm mcallaghan-bsm changed the title docker+venv, stdout is not printed per test rendering sugar moot docker+venv, stdout is not printed per test before running test May 29, 2019
@badarsebard
Copy link

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.

@Teemu
Copy link
Owner

Teemu commented Aug 25, 2020

PYTHONUNBUFFERED?

@Teemu Teemu added the question label Aug 25, 2020
@Teemu
Copy link
Owner

Teemu commented Aug 25, 2020

Or do you mean just the fact that nothing gets displayed before test is ran (i.e. is this related to Docker)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants