Skip to content

Instantly share code, notes, and snippets.

@antocuni
Last active April 16, 2019 15:33
Show Gist options
  • Save antocuni/b444c2c8b37821a95f45bee42e78d3cf to your computer and use it in GitHub Desktop.
Save antocuni/b444c2c8b37821a95f45bee42e78d3cf to your computer and use it in GitHub Desktop.
pytest capture bug
# if you uncomment this, the test works as expected
import dummy
#include <Python.h>
#include <iostream>
static PyMethodDef dummy_methods[] = {
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC initdummy(void) {
PyObject* dummy_module = Py_InitModule3("dummy", dummy_methods,
"dummy module");
// if you comment out this, test_noflush works as expected
std::cout << "Initialising dummy..." << std::endl;
}
from setuptools import setup, Extension
setup(
name="dummy",
ext_modules = [Extension('dummy', ['dummy.cpp'])],
)
import sys
import time
def test_noflush(capfd):
with capfd.disabled():
for i in range(10):
sys.stdout.write('%d\n' % i)
# if you uncomment this, you can see the output again
#sys.stdout.flush()
time.sleep(0.2)
def test_enter_pdb():
0/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment