Refactor smoke_test.py test fixtures #585
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Refactor fixtures such that each test uses its own cmake source and build directory, rather than reusing them across tests. This helps those tests that need to mutate the source directory, and also prevents pytest-ordering issues or workarounds by never reusing a build directory.
Motivation
The session scope
basic_setup
and thetmpdirs
fixture, on top of setting up aCONAN_HOME
that is custom to the entire test session, set the current working directory of all tests to be the same. The function-scope fixtureschdir_build
andchdir_build_multi
then simply chdir into either build directory. Additionally, the conan provider is copied to this working directory alongside the sources. This has some problems:--fresh
to the cmake invocation (to ignore anything that was there beforehand), or to have class-scope fixtures to delete the contents of the build directory, if it exists. One test, however, relies on an already initialized build directory to exist.Detailed changes
conan_home_dir
: sets theCONAN_HOME
environment variablesetup_conan_home
: exports the relevant recipespytest
's built-intmp_path_factory
ortmp_path
fixtures, rather than doing this manually viatempfile
- pytest handles the automatic deletion of past temporary directories and there's no need to do that ourselves.basic_cmake_project
test-level fixture:setup_cmake_workdir()
(new function) to copy the contents of the basic cmake project for testingchdir
into itconan_provider.cmake
file - It's static and is not mutated by any of the tests, and it doesn't need to be copied.Refactors:
The above changes enable the following:
TestBasic
class assumes a re-used build directory, and a separatebuild-multi
directory - this is now handled in a newsetup_basic_test_workdir()
class-level fixture. This is done to enable minimal changes to the already existing tests in this classbasic_cmake_project
, each can mutate the contents of the source directory by copying the extra files from the resources directory.TestSubdir
uses a custom setup (different resources) - so handle it with a custom fixture in that classTestSubdir
to support Windows - there's no reason why it wasn't supported--fresh
to CMake - they're all fresh now, because the build directory is empty when using thebasic_cmake_project
fixturebasic_cmake_project
.