I'm trying to use TDD (test-driven development) with pytest
.
pytest
will not print
to the console when I use print
.
I am using pytest my_tests.py
to run it.
The documentation
seems to say that it should work by default: http://pytest.org/latest/capture.html
But:
import myapplication as tum
class TestBlogger:
@classmethod
def setup_class(self):
self.user = "alice"
self.b = tum.Blogger(self.user)
print "This should be printed, but it won't be!"
def test_inherit(self):
assert issubclass(tum.Blogger, tum.Site)
links = self.b.get_links(posts)
print len(links) # This won't print either.
Nothing gets printed to my standard output console (just the normal progress and how many many tests passed/failed).
And the script that I'm testing contains print:
class Blogger(Site):
get_links(self, posts):
print len(posts) # It won't get printed in the test.
In unittest
module, everything gets printed by default, which is exactly what I need. However, I wish to use pytest
for other reasons.
Does anyone know how to make the print statements get shown?
sys.stdout.write("Test")
? How aboutsys.__stdout__.write("Test")
? The latter should always write to the system-defined stdout, which should be the console. If the two commands do different things, then stdout is being changed; if they do the same thing, then the problem is something else. – TheSoundDefense