Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.4.4: pytest is failing #317

Open
kloczek opened this issue Sep 4, 2021 · 3 comments
Open

0.4.4: pytest is failing #317

kloczek opened this issue Sep 4, 2021 · 3 comments

Comments

@kloczek
Copy link

kloczek commented Sep 4, 2021

I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account.

  • "setup.py build"
  • "setup.py install --root </install/prefix>"
  • "pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Looks like it colorama.tests module is not installed and it is kind of assumption that tested will be source tree and not what actiually is installed (which is very untypical)

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-colorama-0.4.4-3.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-colorama-0.4.4-3.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=1015702682
rootdir: /home/tkloczko/rpmbuild/BUILD/colorama-0.4.4
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, anyio-3.3.0, asyncio-0.15.1, trio-0.7.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0, Faker-8.12.1, nose2pytest-1.0.8, pyfakefs-4.5.1, tornado-0.8.1, twisted-1.13.3
collected 0 items / 5 errors

================================================================================== ERRORS ==================================================================================
_______________________________________________________________ ERROR collecting colorama/tests/ansi_test.py _______________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/colorama-0.4.4/colorama/tests/ansi_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'colorama.tests'
___________________________________________________________ ERROR collecting colorama/tests/ansitowin32_test.py ____________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/colorama-0.4.4/colorama/tests/ansitowin32_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'colorama.tests'
____________________________________________________________ ERROR collecting colorama/tests/initialise_test.py ____________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/colorama-0.4.4/colorama/tests/initialise_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'colorama.tests'
______________________________________________________________ ERROR collecting colorama/tests/isatty_test.py ______________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/colorama-0.4.4/colorama/tests/isatty_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'colorama.tests'
_____________________________________________________________ ERROR collecting colorama/tests/winterm_test.py ______________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/colorama-0.4.4/colorama/tests/winterm_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'colorama.tests'
========================================================================= short test summary info ==========================================================================
ERROR colorama/tests/ansi_test.py
ERROR colorama/tests/ansitowin32_test.py
ERROR colorama/tests/initialise_test.py
ERROR colorama/tests/isatty_test.py
ERROR colorama/tests/winterm_test.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================ 5 errors in 0.34s =============================================================================
pytest-xprocess reminder::Be sure to terminate the started process by running 'pytest --xkill' if you have not explicitly done so in your fixture with 'xprocess.getinfo(<process_name>).terminate()'.
@kloczek
Copy link
Author

kloczek commented Jan 10, 2022

Looks like below patch fixe all relative imports.

--- a/colorama/tests/winterm_test.py~   2020-10-13 05:46:33.000000000 +0100
+++ b/colorama/tests/winterm_test.py    2022-01-10 15:25:56.441529729 +0000
@@ -7,7 +7,7 @@
 except ImportError:
     from mock import Mock, patch

-from ..winterm import WinColor, WinStyle, WinTerm
+from colorama.winterm import WinColor, WinStyle, WinTerm


 class WinTermTest(TestCase):
--- a/colorama/tests/isatty_test.py~    2020-10-13 05:46:33.000000000 +0100
+++ b/colorama/tests/isatty_test.py     2022-01-10 15:26:08.247639829 +0000
@@ -2,8 +2,8 @@
 import sys
 from unittest import TestCase, main

-from ..ansitowin32 import StreamWrapper, AnsiToWin32
-from .utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY
+from colorama.ansitowin32 import StreamWrapper, AnsiToWin32
+from colorama.tests.utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY


 def is_a_tty(stream):
--- a/colorama/tests/ansi_test.py~      2020-10-13 05:46:33.000000000 +0100
+++ b/colorama/tests/ansi_test.py       2022-01-10 15:26:18.470735151 +0000
@@ -2,8 +2,8 @@
 import sys
 from unittest import TestCase, main

-from ..ansi import Back, Fore, Style
-from ..ansitowin32 import AnsiToWin32
+from colorama.ansi import Back, Fore, Style
+from colorama.ansitowin32 import AnsiToWin32

 stdout_orig = sys.stdout
 stderr_orig = sys.stderr
--- a/colorama/tests/ansitowin32_test.py~       2020-10-13 05:46:33.000000000 +0100
+++ b/colorama/tests/ansitowin32_test.py        2022-01-10 15:26:35.343892509 +0000
@@ -7,8 +7,8 @@
 except ImportError:
     from mock import MagicMock, Mock, patch

-from ..ansitowin32 import AnsiToWin32, StreamWrapper
-from .utils import osname
+from colorama.ansitowin32 import AnsiToWin32, StreamWrapper
+from colorama.tests.utils import osname


 class StreamWrapperTest(TestCase):
--- a/colorama/tests/initialise_test.py~        2020-10-13 05:46:33.000000000 +0100
+++ b/colorama/tests/initialise_test.py 2022-01-10 15:26:48.016010677 +0000
@@ -8,9 +8,9 @@
 except ImportError:
     from mock import patch

-from ..ansitowin32 import StreamWrapper
-from ..initialise import init
-from .utils import osname, redirected_output, replace_by
+from colorama.ansitowin32 import StreamWrapper
+from colorama.initialise import init
+from colorama.tests.utils import osname, redirected_output, replace_by

 orig_stdout = sys.stdout
 orig_stderr = sys.stderr
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-colorama-0.4.4-5.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-colorama-0.4.4-5.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/colorama-0.4.4
collected 49 items

colorama/tests/ansi_test.py ...                                                                                                                                      [  6%]
colorama/tests/ansitowin32_test.py ....................                                                                                                              [ 46%]
colorama/tests/initialise_test.py sssssssssss                                                                                                                        [ 69%]
colorama/tests/isatty_test.py .......                                                                                                                                [ 83%]
colorama/tests/winterm_test.py sss....s                                                                                                                              [100%]

========================================================================= short test summary info ==========================================================================
SKIPPED [1] colorama/tests/initialise_test.py:117: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:99: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:90: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:69: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:61: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:49: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:56: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:82: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:74: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:79: sys.stdout is not a tty
SKIPPED [1] colorama/tests/initialise_test.py:42: sys.stdout is not a tty
SKIPPED [1] colorama/tests/winterm_test.py:77: requires Windows
SKIPPED [1] colorama/tests/winterm_test.py:66: requires Windows
SKIPPED [1] colorama/tests/winterm_test.py:25: requires Windows
SKIPPED [1] colorama/tests/winterm_test.py:88: requires Windows
====================================================================== 34 passed, 15 skipped in 0.22s ======================================================================

Please let me know if you want this as PR.

@tartley
Copy link
Owner

tartley commented Oct 25, 2022

You are absolutely right, this should definitely be done. Thanks for the report and the diffs, I'll try and implement it right now.

@kloczek
Copy link
Author

kloczek commented Nov 1, 2022

updated patch for 0.4.6

--- a/colorama/tests/winterm_test.py
+++ b/colorama/tests/winterm_test.py
@@ -7,7 +7,7 @@
 except ImportError:
     from mock import Mock, patch

-from ..winterm import WinColor, WinStyle, WinTerm
+from colorama.winterm import WinColor, WinStyle, WinTerm


 class WinTermTest(TestCase):
--- a/colorama/tests/isatty_test.py
+++ b/colorama/tests/isatty_test.py
@@ -2,8 +2,8 @@
 import sys
 from unittest import TestCase, main

-from ..ansitowin32 import StreamWrapper, AnsiToWin32
-from .utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY
+from colorama.ansitowin32 import StreamWrapper, AnsiToWin32
+from colorama.tests.utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY


 def is_a_tty(stream):
--- a/colorama/tests/ansi_test.py
+++ b/colorama/tests/ansi_test.py
@@ -2,8 +2,8 @@
 import sys
 from unittest import TestCase, main

-from ..ansi import Back, Fore, Style
-from ..ansitowin32 import AnsiToWin32
+from colorama.ansi import Back, Fore, Style
+from colorama.ansitowin32 import AnsiToWin32

 stdout_orig = sys.stdout
 stderr_orig = sys.stderr
--- a/colorama/tests/ansitowin32_test.py
+++ b/colorama/tests/ansitowin32_test.py
@@ -12,9 +12,9 @@
 except ImportError:
     from mock import MagicMock, Mock, patch

-from ..ansitowin32 import AnsiToWin32, StreamWrapper
-from ..win32 import ENABLE_VIRTUAL_TERMINAL_PROCESSING
-from .utils import osname
+from colorama.ansitowin32 import AnsiToWin32, StreamWrapper
+from colorama.win32 import ENABLE_VIRTUAL_TERMINAL_PROCESSING
+from colorama.tests.utils import osname


 class StreamWrapperTest(TestCase):
--- a/colorama/tests/initialise_test.py
+++ b/colorama/tests/initialise_test.py
@@ -7,9 +7,9 @@
 except ImportError:
     from mock import patch, Mock

-from ..ansitowin32 import StreamWrapper
-from ..initialise import init, just_fix_windows_console, _wipe_internal_state_for_tests
-from .utils import osname, replace_by
+from colorama.ansitowin32 import StreamWrapper
+from colorama.initialise import init, just_fix_windows_console, _wipe_internal_state_for_tests
+from colorama.tests.utils import osname, replace_by

 orig_stdout = sys.stdout
 orig_stderr = sys.stderr

It is as well second issue as well. Files from colorama/tests are installed.
That directory shouild be excluded in pyproject.toml or MANIFEST.in file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants