Skip to content

Commit

Permalink
don't send report from xdist workers
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmadurga committed Mar 10, 2023
1 parent bea751c commit e5c4bb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pytest_tinybird/tinybird.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def report(self, session: Session):
terminalreporter: TerminalReporter = session.config.pluginmanager.get_plugin(
"terminalreporter"
)
# special check for pytest-xdist plugin, we do not want to send report for each worker.
if hasattr(terminalreporter.config, 'workerinput'):
return
report = []
for k in terminalreporter.stats:
for test in terminalreporter.stats[k]:
Expand All @@ -60,7 +63,7 @@ def report(self, session: Session):
data=data,
timeout=REQUEST_TIMEOUT)
if response.status_code != 202:
log.error("Error while uploading to tinybird")
log.error("Error while uploading to tinybird %s", response.status_code)

@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(self, session: Session, exitstatus: Union[int, ExitCode]):
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ flake8==6.0.0
pylint==2.16.2
pytest==7.2.1
requests>=2.28.1
pytest-xdist==2.5.0
tox==4.2.8

7 changes: 6 additions & 1 deletion tests/test_tinybird.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ def test_report_to_tinybird(testdir):
# create a temporary pytest test module
testdir.makepyfile("""
import pytest
from random import randint
def test_passed():
assert True
""")
def test_flaky():
assert randint(1,10) >=5
""")

tinybird_url = os.environ["TINYBIRD_URL"] = 'https://fake-api.tinybird.co'
datasource_name = os.environ["TINYBIRD_DATASOURCE"] = "test_datasource"
tinybird_token = os.environ["TINYBIRD_TOKEN"] = 'test_token'

with mock.patch('requests.post') as mock_post:
mock_post.return_value.status_code = 202
testdir.runpytest(
"-n 2",
'--report-to-tinybird',
'-vvv'
)
Expand Down

0 comments on commit e5c4bb5

Please sign in to comment.