首页 > 解决方案 > Segmentation Fault on mysql.connector.connect() only during git action pytest

问题描述

Running my pytest locally it causes no issue but when it gets run using git actions it throws a segmentation fault. Its trying to connect to an AWS RDS database and can connect locally.

I've tried to add error handling but I get no more logs from it.

The connection Function

def create_db_connection():
    """Sets up a mysql connection and returns the connection"""
    try:
        connection = mysql.connector.connect(
        host=URL,
        user=USERNAME,
        password=PASSWORD,
        database=DATABASE
        )
        return connection
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            print("Something is wrong with your user name or password")
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            print("Database does not exist")
        else:
            print(err)

The function that is calling it

def water_consumption_impact(details):
    """Calculates the climate impact of water consumption"""
    annual_production = float(details["mining"]["annual_production"])
    total = float(details["mining"]["water_consumption"])
    connection = create_db_connection()
    impact = run_query(connection,
                        "SELECT climate_change_total FROM LCI_Data WHERE id = 8331;")[0][0]
    return calculate_impact(total, impact, annual_production)

The error on git actions on command

- run: python3 -m pytest -s --cov=src --cov-report xml:reports/unit/coverage.xml

The actual error itself

Run python3 -m pytest -s --cov=src --cov-report xml:reports/unit/coverage.xml
============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/runner/work/aws-python/aws-python
plugins: cov-2.10.1
collected 36 items

Fatal Python error: Segmentation fault

Current thread 0x00007fdaa61ca740 (most recent call first):
  File "/usr/lib/python3.6/ssl.py", line 391 in __new__
  File "/usr/lib/python3.6/ssl.py", line 502 in create_default_context
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/network.py", line 448 in switch_to_ssl
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 201 in _do_auth
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 292 in _open_connection
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/abstracts.py", line 966 in connect
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/connection.py", line 104 in __init__
  File "/home/runner/.local/lib/python3.6/site-packages/mysql/connector/__init__.py", line 265 in connect
  File "/home/runner/work/aws-python/aws-python/src/database_manager.py", line 20 in create_db_connection
  File "/home/runner/work/aws-python/aws-python/src/engine.py", line 103 in water_consumption_impact
  File "/home/runner/work/aws-python/aws-python/src/tests/engine_test.py", line 136 in test_water_consumption_impact
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/python.py", line 184 in pytest_pyfunc_call
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/python.py", line 1627 in runtest
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 163 in pytest_runtest_call
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 256 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 310 in from_call
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 256 in call_runtest_hook
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 216 in call_and_report
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 127 in runtestprotocol
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/runner.py", line 110 in pytest_runtest_protocol
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/main.py", line 338 in pytest_runtestloop
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/main.py", line 313 in _main
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/main.py", line 257 in wrap_session
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/main.py", line 306 in pytest_cmdline_main
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/runner/.local/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 165 in main
  File "/home/runner/.local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 187 in console_main
  File "/home/runner/.local/lib/python3.6/site-packages/pytest/__main__.py", line 5 in <module>
  File "/usr/lib/python3.6/runpy.py", line 85 in _run_code
  File "/usr/lib/python3.6/runpy.py", line 193 in _run_module_as_main
/home/runner/work/_temp/1f3e8867-d3f8-4838-a490-4dd24a3eafc8.sh: line 1:  2479 Segmentation fault      (core dumped) python3 -m pytest -s --cov=src --cov-report xml:reports/unit/coverage.xml

标签: pythongitamazon-web-servicespytestmysql-connector

解决方案


推荐阅读