मैं TDD (परीक्षण-संचालित विकास) का उपयोग करने की कोशिश कर रहा हूं pytest।
जब मैं उपयोग करूँगा तो कंसोल pytestको नहीं ।printprint
मैं pytest my_tests.pyइसे चलाने के लिए उपयोग कर रहा हूं ।
ऐसा documentationलगता है कि यह डिफ़ॉल्ट रूप से काम करना चाहिए: http://pytest.org/latest/capture.html
परंतु:
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.
मेरे मानक आउटपुट कंसोल (केवल सामान्य प्रगति और कितने परीक्षण उत्तीर्ण / असफल हुए) के लिए कुछ भी नहीं छापा जाता है।
और जो स्क्रिप्ट मैं परीक्षण कर रहा हूं उसमें प्रिंट शामिल है:
class Blogger(Site):
get_links(self, posts):
print len(posts) # It won't get printed in the test.
में unittestमॉड्यूल, सब कुछ डिफ़ॉल्ट रूप से मुद्रित हो जाता है, जो कि मैं वास्तव में क्या जरूरत है। हालांकि, मैं pytestअन्य कारणों से उपयोग करना चाहता हूं ।
क्या किसी को पता है कि प्रिंट स्टेटमेंट कैसे दिखाए जाते हैं?
sys.stdout.write("Test")? कैसे के बारे मेंsys.__stdout__.write("Test")? उत्तरार्द्ध को हमेशा सिस्टम-परिभाषित स्टडआउट को लिखना चाहिए, जो कंसोल होना चाहिए। यदि दोनों कमांड अलग-अलग काम करते हैं, तो स्टडआउट को बदला जा रहा है; यदि वे एक ही काम करते हैं, तो समस्या कुछ और है।