AbdealiJK

PyTest and Nose comparison of results

May 19th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. # Run nose using : nosetests --verbosity=2 --with-ignore-docstrings
  2. # Run pytest using : py.test -vvv
  3.  
  4. # Run the script using : python <scriptname> /path/to/pytest/log/file/from/travis /path/to/nose/log/file/from/travis
  5. # Example of nose and pytest logs from travis:
  6. # - Nose - https://travis-ci.org/AbdealiJK/pywikibot-core/builds/131404927
  7. # - PyTest - https://travis-ci.org/AbdealiJK/pywikibot-core/builds/131373171
  8.  
  9. import re
  10. import sys
  11.  
  12. assert len(sys.argv) == 3, 'PyTest log and Nose log required'
  13. pylogfile, noselogfile = sys.argv[1:]
  14.  
  15. with open(pylogfile) as f:
  16.     pylog = f.read()
  17.  
  18. with open(noselogfile) as f:
  19.     noselog = f.read()
  20.  
  21. NOSE_RE = re.compile(r'(?P<funcname>test.*) \((?P<pkgname>.*)\) \.\.\.')
  22. PYTEST_RE = re.compile(r'(?P<filename>tests/.*)\.py::(?P<clsname>.*)::(?P<funcname>[^ ]*) ')
  23.  
  24. pytests = []
  25. for match in re.finditer(PYTEST_RE, pylog):
  26.     match = match.groupdict()
  27.  
  28.     filename = match['filename']
  29.     clsname = match['clsname']
  30.     funcname = match['funcname']
  31.  
  32.     testname = filename + ":" + clsname + "." + funcname
  33.     pytests.append(testname.strip())
  34.  
  35. nosetests = []
  36. for match in re.finditer(NOSE_RE, noselog):
  37.     match = match.groupdict()
  38.  
  39.     filename1, filename2, clsname = match['pkgname'].split('.')
  40.     funcname = match['funcname']
  41.     filename = filename1 + '/' + filename2
  42.  
  43.     testname = filename + ":" + clsname + "." + funcname
  44.     nosetests.append(testname.strip())
  45.  
  46. from pprint import pprint
  47. print('In pytest, but not in nose:',
  48.       len(pytests), '-', len(nosetests),
  49.       '=', len(set(pytests) - set(nosetests)))
  50. pprint(set(pytests) - set(nosetests))
  51. print('In nose, but not in pytest:',
  52.       len(nosetests), '-', len(pytests),
  53.       '=', len(set(nosetests) - set(pytests)))
  54. pprint(set(nosetests) - set(pytests))
  55.  
  56. # pprint(pytests)
  57. # print(len(pytests))
Add Comment
Please, Sign In to add comment