qiskit/Makefile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.8 KiB
Makefile
Raw Normal View History

# This code is part of Qiskit.
2017-05-12 00:12:57 +08:00
#
# (C) Copyright IBM 2017.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
OS := $(shell uname -s)
ifeq ($(OS), Linux)
NPROCS := $(shell grep -c ^processor /proc/cpuinfo)
else ifeq ($(OS), Darwin)
NPROCS := 2
else
NPROCS := 0
endif # $(OS)
ifeq ($(NPROCS), 2)
CONCURRENCY := 2
else ifeq ($(NPROCS), 1)
CONCURRENCY := 1
else ifeq ($(NPROCS), 3)
CONCURRENCY := 3
else ifeq ($(NPROCS), 0)
CONCURRENCY := 0
else
CONCURRENCY := $(shell echo "$(NPROCS) 2" | awk '{printf "%.0f", $$1 / $$2}')
endif
2019-06-03 00:06:24 +08:00
.PHONY: env lint test test_ci
2017-05-08 21:25:14 +08:00
# Dependencies need to be installed on the Anaconda virtual environment.
2017-05-08 21:25:14 +08:00
env:
if test $(findstring qiskitenv, $(shell conda info --envs | tr '[:upper:]' '[:lower:]')); then \
bash -c "source activate Qiskitenv;pip install -r requirements.txt"; \
else \
conda create -y -n Qiskitenv python=3; \
bash -c "source activate Qiskitenv;pip install -r requirements.txt"; \
fi;
# Ignoring generated ones with .py extension.
2017-05-08 21:25:14 +08:00
lint:
pylint -rn qiskit test
tools/verify_headers.py qiskit test tools examples
pylint -rn --disable='C0103, C0114, W0621' examples/python/*.py
tools/find_optional_imports.py
style:
black --check qiskit test tools examples setup.py
black:
black qiskit test tools examples setup.py
2017-05-08 21:25:14 +08:00
# Use the -s (starting directory) flag for "unittest discover" is necessary,
# otherwise the QuantumCircuit header will be modified during the discovery.
2017-05-09 04:17:43 +08:00
test:
@echo ================================================
@echo Consider using tox as suggested in the CONTRIBUTING.MD guideline. For running the tests as the CI, use test_ci
@echo ================================================
python3 -m unittest discover -s test/python -t . -v
@echo ================================================
@echo Consider using tox as suggested in the CONTRIBUTING.MD guideline. For running the tests as the CI, use test_ci
@echo ================================================
# Use pytest to run tests
pytest:
pytest test/python
# Use pytest to run randomized tests
pytest_randomized:
pytest test/randomized
test_ci:
@echo Detected $(NPROCS) CPUs running with $(CONCURRENCY) workers
Add support for attachments to test execution (#3982) * Add support for attachments to test execution By default in CI and with tox locally we run all the tests in parallel. However, this makes things like printing to stdout, warnings on stderr, or logging during tests difficult to deal with. This is because we'll have multiple writers to the output streams simultaneously and no way to figure out which text goes to which test. Luckily stestr and the subunit protocl it uses internally has a method for adding attachments to test results to handle this kind of case. Using this each output stream is associated with the test which generated it and will get displayed as such. The only issue with this is that the stdlib unittest doesn't know how to write attachments to it's result stream. There is a unittest extension library testtools[1] that provides this functionality in a strictly compatible manner with unittest, however the current state of the library needs some work before it can work well with more modern features of stdlib unittest from python>3.5 so we either have to change the tests to not use these features or come up with an alternative solution for test attachments. This commit ports the necessary result streaming functionality from testtools into the QiskitTestCase base test class and then sets up the appropriate fixtures to attach output streams from each test. This works around the current limitation with testtools (I'm slowly working on fixing this in testtools) but still provides the functionality. When testtools is at the point it can be a drop in replacement for unittest as terra is using it we can drop this code. As part of this change all the test classes that define a setUp have a missing super() call added. This framework does not work without setUp in the base class being defined since that's what is used to setup the stream capture. Moving forward the base test class actually enforces that super() is called, otherwise the tests will fail. [1] https://github.com/testing-cabal/testtools * Fix lint * Update contributing doc * Fix copy paste error * Add missing super calls from new tests * Add missing super() calls and fix skip message * Fix lint Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
2020-09-10 07:01:54 +08:00
QISKIT_TEST_CAPTURE_STREAMS=1 stestr run --concurrency $(CONCURRENCY)
test_randomized:
python3 -m unittest discover -s test/randomized -t . -v
coverage:
coverage3 run --source qiskit -m unittest discover -s test/python -q
coverage3 report
coverage_erase:
coverage erase
clean: coverage_erase ;