1 year ago
#203758
brewcrazy
pytest -rP logs twice for each test
I'm building a test suite for a small Django app and am using pytest. When I run the tests with docker-composec -f local.yml run --rm django pytest -rP
, it logs each test twice. I added a timestamp to the function being tested (2022-02-20 20:57:32.196975+00:00
) and they are identical so I don't think its running the tests twice, but outputting them twice.
_______________________________________________________________________________________________________ TestAggregateTiltReadings.test_initial_run _______________________________________________________________________________________________________
------------------------------------------------------------------------------------------------------------------ Captured stderr call ------------------------------------------------------------------------------------------------------------------
INFO 2022-02-20 20:57:32,196 services 1 140188905805632 2022-02-20 20:57:32.196975+00:00
INFO 2022-02-20 20:57:32,197 services 1 140188905805632 Aggregating 4 new tilt readings
------------------------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------------------------
INFO brew_dash.tilts.services:services.py:33 2022-02-20 20:57:32.196975+00:00
INFO brew_dash.tilts.services:services.py:34 Aggregating 4 new tilt readings
_______________________________________________________________________________________________________ TestAggregateTiltReadings.test_initial_run _______________________________________________________________________________________________________
------------------------------------------------------------------------------------------------------------------ Captured stderr call ------------------------------------------------------------------------------------------------------------------
INFO 2022-02-20 20:57:32,196 services 1 140188905805632 2022-02-20 20:57:32.196975+00:00
INFO 2022-02-20 20:57:32,197 services 1 140188905805632 Aggregating 4 new tilt readings
------------------------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------------------------
INFO brew_dash.tilts.services:services.py:33 2022-02-20 20:57:32.196975+00:00
INFO brew_dash.tilts.services:services.py:34 Aggregating 4 new tilt readings
I used cookiecutter-django to start the app and am using the default settings. I'm not sure what configs to share which might be helpful to troubleshoot this. I can add some if there are any ideas.
EDIT
pytest.ini:
[pytest]
addopts = --ds=config.settings.test --reuse-db
python_files = tests.py test_*.py
Using docker-compose -f local.yml run --rm django pytest . -rP --capture=no
_______________________________________________________________________________________________________ TestAggregateTiltReadings.test_initial_run _______________________________________________________________________________________________________
------------------------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------------------------
INFO brew_dash.tilts.services:services.py:33 2022-02-21 02:38:09.635703+00:00
INFO brew_dash.tilts.services:services.py:34 Aggregating 4 new tilt readings
_______________________________________________________________________________________________________ TestAggregateTiltReadings.test_initial_run _______________________________________________________________________________________________________
------------------------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------------------------
INFO brew_dash.tilts.services:services.py:33 2022-02-21 02:38:09.635703+00:00
INFO brew_dash.tilts.services:services.py:34 Aggregating 4 new tilt readings
EDIT 2 the offending test:
@pytest.mark.django_db
class TestAggregateTiltReadings:
def test_initial_run(self, tilt_hydrometer_factory, tilt_reading_factory, caplog):
next_cutoff_dts = timezone.now()
tilt = tilt_hydrometer_factory.create()
# Ensure there's a few TILT readings as would be expected for an initial run
tilt_reading_factory.create(tilt_hydrometer_uuid=tilt)
tilt_reading_factory.create(tilt_hydrometer_uuid=tilt)
tilt_reading_factory.create(tilt_hydrometer_uuid=tilt)
tilt_reading_factory.create(tilt_hydrometer_uuid=tilt)
# last_cutoff_date equaling None makes this an initial run test
gravity, temp = aggregate_tilt_readings(tilt, None, next_cutoff_dts)
assert "Aggregating 4 new tilt readings" in caplog.text
assert is_gravity_valid(int(float(gravity) * 1000))
assert is_temp_valid(temp)
django
pytest
pytest-django
cookiecutter-django
0 Answers
Your Answer