For out-of-source builds, the test/functional/test_runner.py is supposed to be run from the build directory which allows it to pick the test/config.ini file generated by the build system. Currently, it works accidently for the following reasons:
- on POSIX systems, when running a created by Autoconf symlink to the
test/functional/test_runner.pyin the source directory, it actually has the source directory location in thesys.path. - on Windows (the
build_msvcdirectory) VS project puts and copies every build artifact into the source tree (which is wrong and ugly).
This PR makes test/functional/test_runner.py work from a build directory in any form (a symbolic link, a hard link, a copy) on all supported platforms, which is highly desirable in the upcoming CMake-based build system.
For the current master branch, this PR has no behaviour change.
Required for https://github.com/hebasto/bitcoin/pull/15.
Steps to reproduce the issue
While the issue is mostly specific to Windows and CMake builds, it is still possible to reproduce it on the current master branch.
- Make an out-of-source build:
$ ./autogen.sh
$ mkdir ../build && cd ../build
$ ../bitcoin/configure
$ make
- Note that Autoconf created a symbolic link
test/functional/test_runner.pyin the../builddirectory:
$ ls -l test/functional/test_runner.py
lrwxrwxrwx 1 hebasto hebasto 47 May 5 17:40 test/functional/test_runner.py -> ../../../bitcoin/test/functional/test_runner.py
which works flawlessly.
- However, replacing this symbolic link with a hard link or a copy of
test/functional/test_runner.pyfrom the source tree will cause the following error:
$ cp ../bitcoin/test/functional/test_runner.py test/functional/test_runner.py
$ ls -l test/functional/test_runner.py
$ ./test/functional/test_runner.py
Temporary test directory at /tmp/test_runner_₿_🏃_20230505_175104
Running Unit Tests for Test Framework Modules
E
======================================================================
ERROR: test_framework (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_framework
Traceback (most recent call last):
File "/usr/lib/python3.10/unittest/loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
ModuleNotFoundError: No module named 'test_framework'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
Early exiting after failure in TestFramework unit tests