Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions tests/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ def test_statement_with_error_trace(cratedb_service):
engine = sa.create_engine(cratedb_service.database.dburi, connect_args={"error_trace": True})
with engine.connect() as connection:
with pytest.raises(sa.exc.ProgrammingError) as ex:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest.raises has a match parameter that accepts regex

Suggested change
with pytest.raises(sa.exc.ProgrammingError) as ex:
with pytest.raises(sa.exc.ProgrammingError, match=re.escape('InvalidColumnNameException["_id" conflicts with system column]')) as ex:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I didn't know that.

Here, I think I had intended to match both variants, now clarified by an inline comment. In this case, I think it is not comfortable to add them to pytest.raises(...)?

# Make sure both variants match, to validate it's actually an error trace.
assert ex.match(re.escape('InvalidColumnNameException["_id" conflicts with system column]'))
assert ex.match(
    'io.crate.exceptions.InvalidColumnNameException: "_id" conflicts with system column'
)

connection.execute(sa.text("CREATE TABLE foo AS SELECT 1 AS _foo"))
assert ex.match(
re.escape('InvalidColumnNameException["_foo" conflicts with system column pattern]')
)
connection.execute(sa.text("CREATE TABLE foo AS SELECT 1 AS _id"))

# Make sure both variants match, to validate it's actually an error trace.
assert ex.match(re.escape('InvalidColumnNameException["_id" conflicts with system column]'))
assert ex.match(
"io.crate.exceptions.InvalidColumnNameException: "
'"_foo" conflicts with system column pattern'
'io.crate.exceptions.InvalidColumnNameException: "_id" conflicts with system column'
)