The way the tests are structured right now makes it difficult to run all of them on an installed version of qiskit-metal.
The way the CI runs the tests is to run
python -m unittest
from the top level of the repo. Since qiskit_metal is in the top level (rather than using a src directory), the repo version of qiskit-metal gets imported by Python rather than the one in site-packages.
The tests are actually packaged inside of qiskit_metal.tests, so you can actually run most of the tests against the installed version of qiskit-metal by changing the working directory to something other than the top level of the repo and then running
python -m unittest discover qiskit_metal.tests
This will run the tests, but a few of them will fail because they to access qiskit_metal/tests/test_data which is not currently included in the package.
One can also try changing directory into qiskit_metal and running
python -m unittest discover tests
to avoid importing the repo qiskit_metal but some of the test code has relative imports out of the tests package to other parts of qiskit-metal so this also fails.
Steps to reproduce the problem
The problem is not being able to do something so it is hard to give a reproducer but some possible cases are given above. For testing a solution, one could:
Install qiskit_metal
Introduce a bug into the qiskit_metal in the repo
Confirm that the tests still run without encountering the bug
What is the expected behavior?
There is a way to run the tests against the installed version of qiskit_metal.
Suggested solutions
There are a couple options:
Include qiskit_metal/tests/test_data in the package. It is small in size compared to the tests files already included, though including test code in a package is not that common.
Move the tests up out of qiskit_metal, so one could run them without needing to add the top level of the repo to the Python path. This would require a little bit of tweaking of the code because some imports assume the test files are inside of the qiskit_metal package.
Information
What is the current behavior?
The way the tests are structured right now makes it difficult to run all of them on an installed version of qiskit-metal.
The way the CI runs the tests is to run
from the top level of the repo. Since
qiskit_metal
is in the top level (rather than using a src directory), the repo version of qiskit-metal gets imported by Python rather than the one in site-packages.The tests are actually packaged inside of
qiskit_metal.tests
, so you can actually run most of the tests against the installed version of qiskit-metal by changing the working directory to something other than the top level of the repo and then runningThis will run the tests, but a few of them will fail because they to access
qiskit_metal/tests/test_data
which is not currently included in the package.One can also try changing directory into
qiskit_metal
and runningto avoid importing the repo qiskit_metal but some of the test code has relative imports out of the tests package to other parts of qiskit-metal so this also fails.
Steps to reproduce the problem
The problem is not being able to do something so it is hard to give a reproducer but some possible cases are given above. For testing a solution, one could:
What is the expected behavior?
There is a way to run the tests against the installed version of qiskit_metal.
Suggested solutions
There are a couple options: