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

Partial fix for pytest on Windows #1338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blmaier
Copy link

@blmaier blmaier commented Nov 22, 2024

Description
This fixes some of the issues running the tests on Windows.

  • Addresses use of os.geteuid() to detect root user
  • Wraps calls to vsg as python vsg so tests don't rely on Unix shebang
  • Normalize Unix and Windows line-ending comparison using str.splitlines()

Additional context
Resolves #1334

The tests fail on Windows with the following

> ___________ ERROR collecting tests/source_file/test_source_file.py ____________
> tests\source_file\test_source_file.py:24: in <module>
>     class testOSError(unittest.TestCase):
> tests\source_file\test_source_file.py:39: in testOSError
>     @unittest.skipIf("SUDO_UID" in os.environ.keys() or os.geteuid() == 0, "We are root. Root always has permissions so test will fail.")
> E   AttributeError: module 'os' has no attribute 'geteuid'

Catch the AttributeError and attempt to check for admin when on Windows

Signed-off-by: Brandon Maier <[email protected]>
A large number of tests fail on Windows with the following error

> ________ test_severity_using_main.test_architecture_with_configuration ________
> [gw0] win32 -- Python 3.8.20 %PREFIX%\python.exe
>
> self = <tests.severity.test_main.test_severity_using_main testMethod=test_architecture_with_configuration>
>
>     def test_architecture_with_configuration(self):
>         try:
> >           subprocess.check_output(["bin/vsg", "-f", self._sArchitectureFileName, "-c", sConfigFile])
>
> tests\severity\test_main.py:86:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ..\_test_env\lib\subprocess.py:415: in check_output
>     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
> ..\_test_env\lib\subprocess.py:493: in run
>     with Popen(*popenargs, **kwargs) as process:
> ..\_test_env\lib\subprocess.py:858: in __init__
>     self._execute_child(args, executable, preexec_fn, close_fds,
...
> E FileNotFoundError: [WinError 2] The system cannot find the file specified
> ..\_test_env\lib\subprocess.py:1327: FileNotFoundError

Tests that call "bin/vsg" are relying on the Unix shebang (e.g.
"#!/usr/bin/python") to launch `vsg` using the Python interpreter, But
this is not supported on Windows. Instead launch `vsg` with Python
directly.

Signed-off-by: Brandon Maier <[email protected]>
Many of the tests that compare `vsg` stdout fail with a warning as
follows.

> First differing element 0:
> 'ERRO[19 chars]1.vhd(7)port_007 -- Change number of spaces after *in* to 4.\r'
> 'ERRO[19 chars]1.vhd(7)port_007 -- Change number of spaces after *in* to 4.'

The tests use `.split('\n')` to split stdout and stderr by the Linux
line terminator '\n'. But on Windows this causes test failures as the
line terminator is '\r\n'.

Instead use Python `.splitlines()`. which will split on both Linux and
Windows style line terminators. `.splitlines()` also removes empty
trailing lines, so we must modify the expected output accordingly.

Signed-off-by: Brandon Maier <[email protected]>
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

Successfully merging this pull request may close these issues.

Tests fail on Windows
1 participant