-1

I'm using Python Hypothesis to write random tests for database. After 1-2 loops of insert the given values to the table I get list index out of range and @seed to reproduce. There is nothing that suppose to fail, I'm not asserting anything yet. How can I debug this?

Thanks

        run_statement("create table t (x int)")
        @given(st.integers(1,10), st.integers(1,10))
        def insert_select(x):
            assume(x)
            run_statement("insert into t values ({})".format(x))
            select_results = run_statement_with_results("select * from t")
            print select_results

        insert_select()

results:

You can add @seed(257907719204305935240373390472712621009) to this test to reproduce this failure.
timeout
error: list index out of range

1 Answers1

0

Unfortunately this test is fundamentally broken:

  • You are sharing database state between executions of your test case, which must not happen or your tests will be irreproducible.
  • You are providing two arguments to @given, but the test function only accepts one.
  • The assume(x) call is pointless, because x can never be falsey

Once those are fixed, the problem may well vanish.

Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19