'Import errors when collecting modules should display the traceback (#1976).
With low verbosity we omit pytest and internal modules, otherwise show all traceback entries.'

@pytest.mark.parametrize('verbose', [0, 1, 2])
def test_show_traceback_import_error(self, testdir, verbose):

    testdir.makepyfile(foo_traceback_import_error='\n                                                            from    bar_traceback_import_error    import    NOT_AVAILABLE\n                                            ', bar_traceback_import_error='')
    testdir.makepyfile('\n                                                            import    foo_traceback_import_error\n                                ')
    args = (('-v',) * verbose)
    result = testdir.runpytest(*args)
    result.stdout.fnmatch_lines(['ImportError    while    importing    test    module*', 'Traceback:', '*from    bar_traceback_import_error    import    NOT_AVAILABLE', '*cannot    import    name    *NOT_AVAILABLE*'])
    assert (result.ret == 2)
    stdout = result.stdout.str()
    for name in ('_pytest', os.path.join('py', '_path')):
        if (verbose == 2):
            assert (name in stdout)
        else:
            assert (name not in stdout)
