diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 203736d..27ac07d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox black + pip install -r requirements.txt - name: Run Tox run: tox @@ -34,6 +34,29 @@ jobs: - name: Run linter run: black --check . + # On windows we want to test only latest python version. + # Everything else will be tested against Linux + test_on_windows: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + update-environment: false + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run tests + run: pytest + test_python_2: runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 879f6bd..6140ece 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /sdk COPY ./requirements.txt /sdk RUN pip install --upgrade pip \ - && pip install pytest -r requirements.txt + && pip install -r requirements.txt COPY . /sdk ENV PYTHONPATH=/sdk diff --git a/backtracepython/child.py b/backtracepython/child.py index c3dbdf6..62e067d 100644 --- a/backtracepython/child.py +++ b/backtracepython/child.py @@ -24,10 +24,12 @@ def eprint(*args, **kwargs): def post_json(full_url, obj): + payload = json.dumps(obj, ignore_nan=True, bigint_as_string=True) if globs.debug_backtrace: - eprint(full_url) - eprint(json.dumps(obj, indent=2, ignore_nan=True)) - payload = json.dumps(obj, ignore_nan=True).encode("utf-8") + data = "Submitting a payload to {},\n {}\n".format(full_url, payload) + eprint(data) + + payload = payload.encode("utf-8") headers = { "Content-Type": "application/json", "Content-Length": len(payload), diff --git a/example/__init__.py b/example/__init__.py index 894d098..e69de29 100644 --- a/example/__init__.py +++ b/example/__init__.py @@ -1,37 +0,0 @@ -import os - -import backtracepython as backtrace - - -def open_file(name): - open(name).read() - - -def main(): - backtrace.initialize( - endpoint=os.getenv( - "BACKTRACE_SUBMISSION_URL", - '"https://submit.backtrace.io/your-universe/token/json"', - ), - attributes={ - "application": "example-app", - "application.version": "1.0.0", - "version": "1.0.0", - }, - ) - - # send an exception from the try/catch block - try: - open_file("not existing file") - except: - backtrace.send_last_exception() - - # send a message - backtrace.send_report("test message") - - # generate and send unhandled exception - open_file("not existing file") - - -if __name__ == "__main__": - main() diff --git a/example/example.py b/example/example.py new file mode 100644 index 0000000..00f668e --- /dev/null +++ b/example/example.py @@ -0,0 +1,37 @@ +import os + +import backtracepython as backtrace + + +def open_file(name): + open(name).read() + + +def main(): + backtrace.initialize( + endpoint=os.getenv( + "BACKTRACE_SUBMISSION_URL", + '"https://submit.backtrace.io/your-universe/token/json"', + ), + attributes={ + "application": "example-app", + "application.version": "1.0.0", + "version": "1.0.0", + }, + ) + + # send an exception from the try/catch block + try: + open_file("not existing file") + except: + backtrace.send_last_exception() + + # send a message + backtrace.send_report("test message") + + # generate and send unhandled exception + open_file("not existing file") + + +if __name__ == "__main__": + main() diff --git a/pytest.ini b/pytest.ini index a635c5c..b51ac33 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] pythonpath = . +faulthandler_timeout = 5 diff --git a/requirements.txt b/requirements.txt index 3d43198..6f4311d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ six simplejson==3.19.3 +pytest +tox +black; python_version > '3.0' diff --git a/setup.py b/setup.py index 0786186..f147442 100644 --- a/setup.py +++ b/setup.py @@ -2,11 +2,10 @@ from setuptools import find_packages, setup -import backtracepython setup( name="backtracepython", - version=backtracepython.version_string, + version="0.3.3", description="Backtrace.io error reporting tool for Python", author="Backtrace.io", author_email="team@backtrace.io", diff --git a/tests/test_basic_flow.py b/tests/test_basic_flow.py index 63d906e..191e06d 100644 --- a/tests/test_basic_flow.py +++ b/tests/test_basic_flow.py @@ -26,7 +26,7 @@ def check_basic_report(obj): source_code_id = obj["threads"][obj["mainThread"]]["stack"][0]["sourceCode"] assert obj["sourceCode"][source_code_id]["path"].endswith( - "tests/exe/simple_report.py" + os.path.join(tests_dir, "exe", "simple_report.py") ) assert obj["sourceCode"][source_code_id]["text"].endswith("\na = b\n") @@ -49,7 +49,9 @@ def check_multi_file(obj): fault_stack = obj["threads"][obj["mainThread"]]["stack"] source_code_id = fault_stack[-1]["sourceCode"] - assert obj["sourceCode"][source_code_id]["path"].endswith("tests/exe/multi_file.py") + assert obj["sourceCode"][source_code_id]["path"].endswith( + os.path.join(tests_dir, "exe", "multi_file.py") + ) lines = obj["sourceCode"][source_code_id]["text"].split("\n") assert lines[fault_stack[-1]["line"] - 1] == "call_a_file(True)" @@ -91,19 +93,11 @@ def log_message(self, format, *args): host, port = httpd.server_address exe_path = os.path.join(exe_dir, exe_name) - stdio_action = None if debug_backtrace else subprocess.PIPE - child = subprocess.Popen( - [sys.executable, exe_path, host, str(port)], - stdout=stdio_action, - stderr=stdio_action, - ) + child = subprocess.Popen([sys.executable, exe_path, host, str(port)]) httpd.handle_request() check_fn(non_local.json_object) child.wait() - if stdio_action is not None: - child.stdout.close() - child.stderr.close() httpd.server_close()