Skip to content

Commit

Permalink
fix: output logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpantos committed Aug 16, 2024
1 parent 40e1c9e commit ae8891a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ bandit-check:

.PHONY: test
test:
poetry run pytest -s -v -n ${MAX_CONCURRENCY} tests
poetry run pytest -s -o log_cli=True --log-cli-level=debug -n ${MAX_CONCURRENCY} tests

.PHONY: coverage
coverage:
poetry run pytest -s -v -n ${MAX_CONCURRENCY} --cov-report term-missing --cov=pantos tests
poetry run pytest -r -o log_cli=True --log-cli-level=debug -n ${MAX_CONCURRENCY} --cov-report term-missing --cov=pantos tests
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import pathlib
import random
import string
import sys
import dotenv
import pytest
import pantos.client as pc

sys.stdout = sys.stderr

if pathlib.Path('.env').exists():
dotenv.load_dotenv('.env')

Expand Down
9 changes: 5 additions & 4 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pathlib
import subprocess
import sys
import dotenv
import pantos.client.library.configuration as pc_conf
import concurrent.futures
Expand All @@ -13,10 +14,10 @@ def run_command(command, cwd, env_vars):
# Merge environment variables
env = {**os.environ, **env_vars}

print(f'Running command: {command} in {cwd} with environment: {env}')
sys.stderr.write(f'Running command: {command} in {cwd} with environment: {env_vars}\n')
process = subprocess.Popen(command, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, bufsize=0)
for line in process.stdout:
print(line.decode(), end='')
sys.stderr.write(line.decode()+ '\n')
process.wait()
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, command)
Expand All @@ -32,11 +33,11 @@ def configure_nodes(config, stack_id):
if not pantos_ethereum_contracts_dir:
raise EnvironmentError('PANTOS_ETHEREUM_CONTRACTS environment variable not set')

print(f'Configuring tests with: Ethereum Contracts {pantos_ethereum_contracts_version}, Service Node {pantos_service_node_version}, Validator Node {pantos_validator_node_version}')
sys.stderr.write(f'Configuring tests with: Ethereum Contracts {pantos_ethereum_contracts_version}, Service Node {pantos_service_node_version}, Validator Node {pantos_validator_node_version}\n')

# Teardown
if not config:
print('Tearing down the environment')
sys.stderr.write('Tearing down the environment\n')
# Dump all the logs
env_vars = {'STACK_IDENTIFIER': stack_id}
with concurrent.futures.ThreadPoolExecutor() as executor:
Expand Down
15 changes: 8 additions & 7 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import decimal
import os
import sys
import time
import pytest
import pantos.client as pc
Expand All @@ -11,7 +12,7 @@
@pytest.fixture(scope="module", autouse=True)
def setup_module(request, stack_id, worker_id = "gw0"):
# Code to set up the environment before any tests in the module
print("Setting up module environment")
sys.stderr.write("Setting up module environment\n")
port_offset = int(worker_id.replace("gw", "")) if worker_id != "master" else 0
#os.environ['PORT_OFFSET'] = str(port_offset)
configure_nodes({
Expand All @@ -29,7 +30,7 @@ def test_retrieve_token_balance(receiving_address):
pc.BlockchainAddress(receiving_address),
pc.TokenSymbol('pan'))
assert token_balance is not None
print(f'Token balance: {token_balance}')
sys.stderr.write(f'Token balance: {token_balance}\n')
except pc.PantosClientError:
pytest.fail("PantosClientError raised")

Expand All @@ -38,7 +39,7 @@ def test_retrieve_service_node_bids():
service_node_bids = pc.retrieve_service_node_bids(pc.Blockchain.ETHEREUM,
pc.Blockchain.BNB_CHAIN, False)
assert service_node_bids is not None
print(f'Service node bids: {service_node_bids}')
sys.stderr.write(f'Service node bids: {service_node_bids}\n')
except pc.PantosClientError:
pytest.fail("PantosClientError raised")

Expand All @@ -51,7 +52,7 @@ def test_token_transfer(receiving_address, private_key):
pc.BlockchainAddress(receiving_address),
pc.TokenSymbol('pan'), decimal.Decimal('1.01'))
assert token_transfer_response is not None
print(f'Token transfer response: {token_transfer_response}')
sys.stderr.write(f'Token transfer response: {token_transfer_response}\n')
except pc.PantosClientError:
pytest.fail("PantosClientError raised")

Expand All @@ -62,13 +63,13 @@ def test_token_transfer(receiving_address, private_key):
pc.Blockchain.ETHEREUM, token_transfer_response.service_node_address,
token_transfer_response.task_id)
assert token_transfer_status is not None
print(f'Token transfer status: {token_transfer_status}')
sys.stderr.write(f'Token transfer status: {token_transfer_status}\n')
if (token_transfer_status.source_transfer_status is ServiceNodeTransferStatus.CONFIRMED):
# TODO: Enable this when we migrate from etherum contracts 1.1.2
#and token_transfer_status.destination_transfer_status is DestinationTransferStatus.CONFIRMED):
done = True
else:
print('Waiting for transfer to be confirmed...')
sys.stderr.write('Waiting for transfer to be confirmed...\n')
time.sleep(5)
except pc.PantosClientError:
pytest.fail("PantosClientError raised")
Expand All @@ -85,6 +86,6 @@ def test_token_transfer(receiving_address, private_key):
# payment_blockchain,
# private_key)
# assert task_id is not None
# print(f'Task ID deployment: {task_id}')
# sys.stderr.write(f'Task ID deployment: {task_id}\n')
# except pc.PantosClientError:
# pytest.fail("PantosClientError raised")

0 comments on commit ae8891a

Please sign in to comment.