Skip to content

Changing to use native pytest #131

@damiansteiger

Description

@damiansteiger

We have discussed this issue before the release and decided to switch to pytest because

  • No boilerplate
  • Better options share test fixtures (more advances version of unittest's setup)
  • Parametrized tests
  • More sensible error messages in certain cases

For example code, browse the tests in ProjectQ.

Our continuous integration testing is therefore since the beginning using pytest instead of unittest. Pytest allows to run the standard unittest files for backwards compatibility and unfortunately our tests are still using unittest.

Could we decide that if we write completely new test files, that these use pytest and not unittest?
Obviously it would also be great if the other tests at some point are refactored but this is not an important issue but we should start somewhere now. I know this means some people will have to learn pytest, but it is easy (see https://docs.pytest.org/en/latest/) and there are already great test examples in ProjectQ for pretty much all cases.

It would also help new users that they see that the best way to testing is going with pytest. For example in #123

self.assertTrue(self.assertTrue(evensector == 2**(n_qubits - 1))

was used and naturally it doesn't give a sensible error message (False not equal True). Of course one can use self.assertEqual instead to get a better error message but such a thing would not have happened with pytest as it is without boilerplate:

assert evensector == 2**(n_qubits - 1)

@maffoo: I remember you were also in favour of pytest. Anymore good reasons to switch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions