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

Windows fatal access exception #168

Open
RedUndercover opened this issue Nov 18, 2024 · 1 comment
Open

Windows fatal access exception #168

RedUndercover opened this issue Nov 18, 2024 · 1 comment

Comments

@RedUndercover
Copy link

I am trying to test some of my rego code in pytest using regopy and keep running into errors:

This is my pytest code:

from regopy import Interpreter
import pytest
import os
import pathlib


def test_rego():
    # Load rego policy
    rego_policy = r"test.rego"
    rego_input = r"ec2_data.json"
    current_dir = pathlib.Path(os.path.abspath(__file__)).parent

    rego_policy = os.path.join(current_dir, rego_policy)
    rego_input = os.path.join(current_dir, rego_input)
    
    with open(rego_policy) as f:
        policy = f.read()

    # Load rego input
    with open(rego_input) as f:
        input_data = f.read()

    # Create rego object
    rego = Interpreter()

    rego.add_module("aws.cost.idle_instances", policy)
    rego.set_input(input_data)
    result = rego.query("data.aws.cost.idle_instances.details")
    assert result is not None

But upon execution of pytest, i get this error:

Windows fatal exception: access violation

Current thread 0x000066e4 (most recent call first):
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\regopy\interpreter.py", line 110 in __init__
  File "c:\Users\Tyler\dev\OpsBox\modules\rego_checks\ec2_checks\idle_instances\test_idle_instances.py", line 25 in test_rego
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\python.py", line 159 in pytest_pyfunc_call
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\python.py", line 1627 in runtest
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 174 in pytest_runtest_call
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 242 in <lambda>
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 341 in from_call
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 241 in call_and_report
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 132 in runtestprotocol
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\runner.py", line 113 in pytest_runtest_protocol
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\main.py", line 362 in pytest_runtestloop
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\main.py", line 337 in _main
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\main.py", line 283 in wrap_session
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\main.py", line 330 in pytest_cmdline_main
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175 in main
  File "C:\Users\Tyler\dev\OpsBox\.venv\Lib\site-packages\_pytest\config\__init__.py", line 201 in console_main
  File "C:\Users\Tyler\dev\OpsBox\.venv\Scripts\pytest.exe\__main__.py", line 8 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

and when running with vscode:
The python test process was terminated before it could exit on its own, the process errored with: Code: 3221225477, Signal: null
This rego code has been confirmed to be working perfectly well in an ordinary OPA server environment.

Here is a modified version of our code:, with one less list argument:

package aws.cost.idle_instances

default allow = false

allow {
    a := input.instances[_]
    a.state == "running"
}

details := [a | a := input.instances[_]; a.state == "running"]

I am on python 3.11 on windows running version 0.4.5 of regopy.

@RedUndercover RedUndercover changed the title Windows Windows fatal access exception Nov 18, 2024
@matajoh
Copy link
Member

matajoh commented Dec 3, 2024

Thanks for the bug report! I will see if I can repro this issue and then investigate. As I use pytest for my own tests, this is unexpected!

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