New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix pytest suite allowing it to complete on Python 3.8 #791
Conversation
Signed-off-by: Nischay Ram Mamidi <NischayPro@gmail.com>
I am trying to run pytest however one of my test fails for Python 3.8 FAILED flexmeasures/api/v3_0/tests/test_sensor_schedules.py::test_trigger_and_get_schedule[message1-Test charging station] - AssertionError: assert False is True More information app = <Flask 'flexmeasures'>, add_market_prices = {'epex_da': <Sensor 1: epex_da, unit: EUR/MWh res.: 1:00:00>, 'epex_da_production': <Sensor 2: epex_da_production, unit: EUR/MWh res.: 1:00:00>}
add_battery_assets = {'Test battery': <GenericAsset 5: 'Test battery' (battery)>, 'Test battery with no known prices': <GenericAsset 6: 'Test battery with no known prices' (battery)>}, battery_soc_sensor = <Sensor 8: state of charge, unit: % res.: 0:00:00>
add_charging_station_assets = {'Test charging station': <GenericAsset 10: 'Test charging station' (one-way_evse)>, 'Test charging station (bidirectional)': <GenericAsset 11: 'Test charging station (bidirectional)' (two-way_evse)>}, keep_scheduling_queue_empty = None
message = {'duration': 'PT24H', 'flex-context': {'consumption-price-sensor': 1, 'production-price-sensor': 1}, 'flex-model': {'r...trip-efficiency': '98%', 'soc-at-start': 12.1, 'soc-max': 40, 'soc-min': 0, ...}, 'start': '2015-01-01T00:00:00+01:00'}
asset_name = 'Test charging station'
@pytest.mark.parametrize(
"message, asset_name",
[
(message_for_trigger_schedule(), "Test battery"),
(message_for_trigger_schedule(with_targets=True), "Test charging station"),
],
)
def test_trigger_and_get_schedule(
app,
add_market_prices,
add_battery_assets,
battery_soc_sensor,
add_charging_station_assets,
keep_scheduling_queue_empty,
message,
asset_name,
):
# Include the price sensor in the flex-context explicitly, to test deserialization
price_sensor_id = add_market_prices["epex_da"].id
message["flex-context"] = {
"consumption-price-sensor": price_sensor_id,
"production-price-sensor": price_sensor_id,
}
# trigger a schedule through the /sensors/<id>/schedules/trigger [POST] api endpoint
assert len(app.queues["scheduling"]) == 0
sensor = (
Sensor.query.filter(Sensor.name == "power")
.join(GenericAsset)
.filter(GenericAsset.id == Sensor.generic_asset_id)
.filter(GenericAsset.name == asset_name)
.one_or_none()
)
with app.test_client() as client:
auth_token = get_auth_token(client, "test_prosumer_user@seita.nl", "testtest")
trigger_schedule_response = client.post(
url_for("SensorAPI:trigger_schedule", id=sensor.id),
json=message,
headers={"Authorization": auth_token},
)
print("Server responded with:\n%s" % trigger_schedule_response.json)
assert trigger_schedule_response.status_code == 200
job_id = trigger_schedule_response.json["schedule"]
# look for scheduling jobs in queue
assert (
len(app.queues["scheduling"]) == 1
) # only 1 schedule should be made for 1 asset
job = app.queues["scheduling"].jobs[0]
assert job.kwargs["sensor_id"] == sensor.id
assert job.kwargs["start"] == parse_datetime(message["start"])
assert job.id == job_id
# process the scheduling queue
work_on_rq(app.queues["scheduling"], exc_handler=handle_scheduling_exception)
> assert (
Job.fetch(job_id, connection=app.queues["scheduling"].connection).is_finished
is True
)
E AssertionError: assert False is True
E + where False = Job('9d3dc3c8-0e39-40fe-8356-9ebcfb525ea9', enqueued_at=datetime.datetime(2023, 8, 4, 12, 42, 1, 470320)).is_finished
E + where Job('9d3dc3c8-0e39-40fe-8356-9ebcfb525ea9', enqueued_at=datetime.datetime(2023, 8, 4, 12, 42, 1, 470320)) = <bound method Job.fetch of <class 'rq.job.Job'>>('9d3dc3c8-0e39-40fe-8356-9ebcfb525ea9', connection=FakeStrictRedis<ConnectionPool<FakeConnection<server=<fakeredis._server.FakeServer object at 0x7f7164ee8a60>,db=0>>>)
E + where <bound method Job.fetch of <class 'rq.job.Job'>> = Job.fetch
E + and FakeStrictRedis<ConnectionPool<FakeConnection<server=<fakeredis._server.FakeServer object at 0x7f7164ee8a60>,db=0>>> = Queue('scheduling').connection
flexmeasures/api/v3_0/tests/test_sensor_schedules.py:219: AssertionError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the exception handler contains more info on why it failed?
@Nischay-Pro we somehow need the log of the worker who handled this job (and couldn't process it). Does that appear somewhere? |
I believe running the application on Python3.8 might already tell us the basic problems. I'm seeing these on the staging server:
2023-08-07 11:19:14,078: File "/var/www/staging_flexmeasures_seita_nl_wsgi.py", line 24, in And then after moving the import of
|
We'll first see if #776 fixes this for 3.8 (it also includes the two conftest future imports already) |
Description
This PR adds the 2 missing
__future__ import annotations
statements in the pytest files. This allowspytest
to run onPython 3.8