2
respostas

Erro com pytest.raises(Exception) - colorama

No windows 10, utilizando o pycharm, ao tentar no venv o comando pytest -v retorna erro com pytest.raises(Exception):

(venv) PS C:\Users\Amilcar Joel Simm\PycharmProjects\tdd> pytest -v============================================================================== test session starts =============================================================================== platform win32 -- Python 3.11.3, pytest-7.4.0, pluggy-1.2.0 -- C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Scripts\python.exe cachedir: .pytest_cache rootdir: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd collected 5 items / 5 errors

===================================================================================== ERRORS ===================================================================================== _________________________________________________________ ERROR collecting Lib/site-packages/colorama/tests/ansi_test.py _________________________________________________________ import file mismatch: imported module 'colorama.tests.ansi_test' has this file attribute: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Lib\site-packages\colorama\tests\ansi_test.py which is not the same as the test file we want to collect: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\Lib\site-packages\colorama\tests\ansi_test.py HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules _____________________________________________________ ERROR collecting Lib/site-packages/colorama/tests/ansitowin32_test.py ______________________________________________________ import file mismatch: imported module 'colorama.tests.ansitowin32_test' has this file attribute: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Lib\site-packages\colorama\tests\ansitowin32_test.py which is not the same as the test file we want to collect: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\Lib\site-packages\colorama\tests\ansitowin32_test.py HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules ______________________________________________________ ERROR collecting Lib/site-packages/colorama/tests/initialise_test.py ______________________________________________________ import file mismatch: imported module 'colorama.tests.initialise_test' has this file attribute: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Lib\site-packages\colorama\tests\initialise_test.py which is not the same as the test file we want to collect: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\Lib\site-packages\colorama\tests\initialise_test.py HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules ________________________________________________________ ERROR collecting Lib/site-packages/colorama/tests/isatty_test.py ________________________________________________________ import file mismatch: imported module 'colorama.tests.isatty_test' has this file attribute: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Lib\site-packages\colorama\tests\isatty_test.py which is not the same as the test file we want to collect: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\Lib\site-packages\colorama\tests\isatty_test.py HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules _______________________________________________________ ERROR collecting Lib/site-packages/colorama/tests/winterm_test.py ________________________________________________________ import file mismatch: imported module 'colorama.tests.winterm_test' has this file attribute: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\venv\Lib\site-packages\colorama\tests\winterm_test.py which is not the same as the test file we want to collect: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd\Lib\site-packages\colorama\tests\winterm_test.py HINT: remove pycache / .pyc files and/or use a unique basename for your test file modules ============================================================================ short test summary info ============================================================================= ERROR Lib/site-packages/colorama/tests/ansi_test.py ERROR Lib/site-packages/colorama/tests/ansitowin32_test.py ERROR Lib/site-packages/colorama/tests/initialise_test.py ERROR Lib/site-packages/colorama/tests/isatty_test.py ERROR Lib/site-packages/colorama/tests/winterm_test.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! =============================================================================== 5 errors in 0.68s ================================================================================

2 respostas

Em tempo... fora do venv funciona (não coloco o verbose por ultrapassar o limite de caracteres):

(tdd) PS C:\Users\Amilcar Joel Simm\PycharmProjects\tdd> pytest============================================================================== test session starts =============================================================================== platform win32 -- Python 3.11.3, pytest-7.4.0, pluggy-1.2.0 rootdir: C:\Users\Amilcar Joel Simm\PycharmProjects\tdd collected 57 items

Lib\site-packages\colorama\tests\ansi_test.py ... [ 5%] Lib\site-packages\colorama\tests\ansitowin32_test.py ....................... [ 45%] Lib\site-packages\colorama\tests\initialise_test.py ssssssssss. [ 64%] Lib\site-packages\colorama\tests\isatty_test.py ....... [ 77%] Lib\site-packages\colorama\tests\winterm_test.py ........ [ 91%] tests\test_bytebank.py ..... [100%]

========================================================================= 47 passed, 10 skipped in 0.70s =========================================================================

Vc tá usando PyTest pra que, exatamente? dentro da sua pasta tdd, deve ter uma pasta pycache com os binários .pyc pra rodar no windows, pode remover essa pasta, talvez gere novamente, mas tá rodando em cache... pior que tá escrito no log de erro...