Sto usando nosetests test.py
per eseguire unit test:Fai la prova di naso corridore show logging, anche se i test passano
import unittest
import logging
class Test(unittest.TestCase):
def test_pass(self):
logging.getLogger('do_not_want').info('HIDE THIS')
logging.getLogger('test').info('TEST PASS')
self.assertEqual(True, True)
def test_fail(self):
logging.getLogger('do_not_want').info('HIDE THIS')
logging.getLogger('test').info('TEST FAIL')
self.assertEqual(True, False)
Quando test ha esito negativo, esso stampa tutte le informazioni di registrazione. Posso usare --logging-filter
per filer fuori solo alcuni logger:
nosetests test.py --verbosity=2 --logging-filter=test
test_fail (test.Test) ... FAIL
test_pass (test.Test) ... ok
======================================================================
FAIL: test_fail (test.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../test.py", line 14, in test_fail
self.assertEqual(True, False)
AssertionError: True != False
-------------------- >> begin captured logging << --------------------
test: INFO: TEST FAIL
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=1)
Tuttavia, non mostra niente quando i test passano.
Mi piacerebbe vedere l'output di uno specifico logger quando i test passano. Ho scoperto che posso usare -s
per mostrare tutto il testo stdout/stderr che non è esattamente quello di cui ho bisogno: stampa tutto. Ho provato a giocare con varie impostazioni come --nologcapture
, --nocapture
o --logging-filter
ma non sono riuscito a ottenere l'effetto desiderato.
Il plug-in logcapture è solo ~ 250 righe. Probabilmente puoi sottoclassi o adattarlo abbastanza facilmente per fare ciò che vuoi. Puoi trovarlo [qui] (https://github.com/nose-devs/nose/blob/master/nose/plugins/logcapture.py). – rkrzr
@Fenikso Hai trovato una soluzione per il problema? – Stefan
@Stefan No, non sembra esistere in Naso. Sto usando alcuni brutti rimedi quando necessario, come scrivere su file. – Fenikso