Skip to content

Commit b519fd9

Browse files
wshanksnkanazawa1989
authored andcommitted
Remove usage of QiskitTestCase (qiskit-community#1285)
This change removes the dependence on `QiskitTestCase`, replacing it with a direct dependence on `unittest.TestCase` and `testtools.TestCase`. As with `QiskitTestCase`, the ability to run the tests based either on `unittest.TestCase` or `testtools.TestCase` (a `unittest.TestCase` subclass) is preserved. For qiskit-experiments, the ability is actually restored because the timeout feature added in [qiskit-community#1246](qiskit-community#1246) had introduced a hard dependence on `testtools`. Specific changes: * Add `testtools` and `fixtures` to `requirements-dev.txt` as required test dependencies. * Use `QE_USE_TESTTOOLS` environment variable to control whether tests are based on `testtools.TestCase` rather than checking if `testtools` is installed. * Remove some checks for test writing best practices. `QiskitTestCase` used extra code to ensure that `setUp` and other test class methods always called their parents and that those methods are not called from individual tests. `testtools.TestCase` does these checks as well. Since qiskit-experiments always uses `testtools` in CI, it can rely on `testtools` for these checks and just not do them for the alternate `unittest` execution. * Generate `QiskitExperimentsTestCase` from a `create_base_test_case` function. This function allows the base test class to be generated based on either `testtools.TestCase` or `unittest.TestCase` so that the `unittest` variant can be tested for regressions even when the `testtools` variant is enabled. Closes [qiskit-community#1282](qiskit-community#1282).
1 parent 7d16410 commit b519fd9

File tree

6 files changed

+298
-190
lines changed

6 files changed

+298
-190
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ Note that tests will fail automatically if they do not finish execution within 6
121121

122122
#### STDOUT/STDERR and logging capture
123123

124-
When running tests in parallel using `stestr` either via tox, the Makefile (`make
125-
test_ci`), or in CI, we set the env variable `QISKIT_TEST_CAPTURE_STREAMS`, which will
124+
When running tests in parallel using `stestr` either via tox
125+
or in CI, we set the env variable `QISKIT_TEST_CAPTURE_STREAMS`, which will
126126
capture any text written to stdout, stderr, and log messages and add them as attachments
127127
to the tests run so output can be associated with the test case it originated from.
128128
However, if you run tests with `stestr` outside of these mechanisms, by default the
@@ -134,6 +134,18 @@ stdlib unittest runner, a similar result can be accomplished by using the
134134
[`--buffer`](https://docs.python.org/3/library/unittest.html#command-line-options)
135135
option (e.g. `python -m unittest discover --buffer ./test/python`).
136136

137+
#### Other testing related settings
138+
139+
The test code defines some environment variables that may occasionally be useful to set:
140+
141+
+ `TEST_TIMEOUT`: An integer representing the maximum time a test can take
142+
before it is considered a failure.
143+
+ `QE_USE_TESTTOOLS`: Set this variable to `FALSE`, `0`, or `NO` to have the
144+
tests use `unittest.TestCase` as the base class. Otherwise, the default is
145+
`testtools.TestCase` which is an extension of `unittest.TestCase`. In some
146+
situations, a developer may wish to use a workflow that is not compatible with
147+
the `testtools` extensions.
148+
137149
### Code style
138150

139151
The qiskit-experiments repository uses `black` for code formatting and style and

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
qiskit-terra>=0.45.0
22
black~=22.0
3+
fixtures
34
stestr
5+
testtools
46
pylint~=3.0.2
57
astroid~=3.0.1 # Must be kept aligned to what pylint wants
68
jinja2==3.0.3

0 commit comments

Comments
 (0)