Skip to content

feat(testing): class based parametrization and fixtures#1135

Open
leshy wants to merge 1 commit intomasterfrom
feat/class_pytest_xdist
Open

feat(testing): class based parametrization and fixtures#1135
leshy wants to merge 1 commit intomasterfrom
feat/class_pytest_xdist

Conversation

@leshy
Copy link
Contributor

@leshy leshy commented Apr 19, 2018

Suggestion for writing tests that resolves all pytest issues I've been having and allows us to parallelize with pytest-xdist (3x speedup on my laptop as of now, expect it to get better as the number of tests grows)

  • some spec multiple systems conform to is defined as a mixin class
  • fixtures via classes and not decorators, (use setUp and tearDown)
  • parametrization via subclassing or pytest decorators
  • easily distributed with optional serial execution of tests within the same class (for tests with side-effects, like storage)

--

(I know there is no buyin for a tag service, we might pivot this week, this just shows how service spec conformity testing would work)

Let's say we'd like to be flexible about where we store tags, we want to be able to exchange providers for tag storage and make sure they all conform to the same spec.

TagCrud is a testing class that tests conformity to this spec.

To make it concrete, you mix it into another class, that instantiates a service we'd like to test, like TestPostgres

this way when we have a RoelofGraphDb, we can just test it with the same TagCrud tests.

most importantly, these classes when tested via pytest-xdist can be executed in parallel giving us significant speedup, yet tests within a class are executed in series, which means that they can have side-effects (CRUD is a good example) and are all run in the same process/thread, which means that setUp and tearDown have to run only once (efficiency and also can have sideeffects (reset the db))

@leshy leshy requested review from alexjc and teropa April 19, 2018 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant