tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.51k stars 249 forks source link

Pytest issues #383

Open johnlabarge opened 7 months ago

johnlabarge commented 7 months ago

Just started a new project and I'm getting all kinds of colorama test failures from pytest: lib/python3.11/site-packages/pip/_vendor/colorama/tests/ansitowin32_test.py::AnsiToWin32Test::test_native_windows_ansi - AssertionError: expected call not found. FAILED lib/python3.11/site-packages/pip/_vendor/colorama/tests/ansitowin32_test.py::AnsiToWin32Test::test_osc_codes - AttributeError: 'NoneType' object has no attribute 'set_title' FAILED lib/python3.11/site-packages/pip/_vendor/colorama/tests/winterm_test.py::WinTermTest::testInit - AttributeError: module 'pip._vendor.colorama.win32' has no attribute 'G... FAILED lib/python3.11/site-packages/pip/_vendor/colorama/tests/winterm_test.py::WinTermTest::testResetAll - AttributeError: module 'pip._vendor.colorama.win32' has no attribute 'G... FAILED lib/python3.11/site-packages/pip/_vendor/colorama/tests/winterm_test.py::WinTermTest::testSetConsole - AttributeError: module 'pip._vendor.colorama.win32' has no attribute 'G... FAILED lib/python3.11/site-packages/pip/_vendor/colorama/tests/winterm_test.py::WinTermTest::testSetConsoleOnStderr - AttributeError: module 'pip._vendor.colorama.win32' has no attribute 'G...

Not sure how to fix these. Python 3.11.7, iniconfig==2.0.0 packaging==23.2 pluggy==1.4.0 pytest==7.4.4 PyYAML==6.0.1

wiggin15 commented 7 months ago

This looks like (at least partly) a problem of running the unittests of colorama on the copy of colorama that's bundled with "pip", which is not intended. For example, the tests "mock" some parts of colorama using calls like patch('colorama.ansitowin32.winterm') but in this case the path to colorama is actually pip._vendor.colorama.ansitowin32.winterm.

I suggest trying to avoid calling tests of external packages that are not part of your project, like pip or colorama. You can do this by either making sure your virtualenv (where the dependencies are installed) is located outside of your project root directory, or configuring "pytest" to exclude directories that are not part of your project.