Unique validation testa "passes" in shell but not in actual test

I have a User schema changeset with:

unique_constraint(:username, message: "Username is already taken")  

And its migration has:

create(unique_index(:users, [:username]))

If I try making a user with an already-existing username in the shell, it fails correctly.

However, I cannot seem to test this. Here’s my current test:

  test "create_user/1 with duplicate username error changeset" do
   # Username here is "terra"
    assert {:ok, %User{} = _user} = Accounts.create_user(@create_attrs)
    # Just changing the email so it doesn't fail unique validation of that, username is still the same
    duplicate_username = @create_attrs |> Map.put(:email, "terra.b@example.com")

    assert {:error, changeset} = Accounts.create_user(duplicate_username)

It just succeeds and created in making the user. Any clues? Some sort of bad testing set up? Thanks.

Does Accounts.create_user/1 actually do a Repo.insert?

Does Accounts.create_user/1 actually do a Repo.insert?

Yes. Here’s its code:

  def create_user(attrs) do
    |> User.create_changeset(attrs)
    |> Repo.insert()

As I mentioned, this works in the shell and application level (i.e. I get an error view), just not in the test.