Rerunning registration test fires an issue that a user is already present in database

Hi,

I have a test that checks if a user can register properly. When I run it for the first time it works, however when I try to run it again I get:
constraint error when attempting to insert struct:

I suspect it’s because the user already exists. What can I do to tell my tests to ‘fake’ creating a user, or delete changes after running this test?

This is my code:

defmodule E2E.LoginTest do
  use ExUnit.Case, async: true
  use Wallaby.Feature

  import Wallaby.Browser
  import Wallaby.Query, only: [text_field: 1, button: 1, css: 2]
  alias Wallaby.{Element, Query}


  feature "a user can register with the system", %{session: session} do
    session
    |> visit("http://localhost:4000/users/new")
    |> fill_in(text_field("Name"), with: "test4")
    |> fill_in(text_field("Username"), with: "test4")
    |> fill_in(text_field("Password"), with: "123Pasword123")
    |> find(Query.text("Create User"), fn el -> Element.click(el) end)

   Process.sleep(10_000)
   assert_text(session, "Listing Users")

  end

You need to use sandbox.

Wallaby should be taking care of this for them.

@borybar i suspect that you created a user in your test database outside of a test transaction. I suggest dropping your test database MIX_ENV=test mix ecto.drop and then retrying the test.