I'm trying to do a python port of some ruby code that uses Cucumber for testing. I'm attempting to use the exact same feature files in the new port. One of the features looks a bit like:
Feature: <whatever>
@with_tmpdir
Scenario: generating a file
Given <some setup stuff>
And file 'test.out' does not exist
When I call <something> with argument 'test.out'
Then a file called 'test.out' is created
And the file called 'test.out' contains:
"""
<some contents>
"""
To support this, the original code has the following in features/support/hooks.rb:
Around('@with_tmpdir') do |scenario, block|
old_pwd = Dir.getwd
Dir.mktmpdir do |dir|
Dir.chdir(dir)
block.call
end
Dir.chdir(old_pwd)
end
Now, I'd like to figure out how to do this sort of thing in behave, presumably/ideally utilizing with tempfile.TemporaryDirectory as tmpdir in place of ruby's Dir.mktmpdir do |dir|.
Alas, I don't see anything to indicate support for Around hooks. It seems like maybe this is the sort of thing that fixtures are meant to do? Can fixtures do what I'm hoping for? If so, how?
Indeed, fixtures can be used to get the behavior you're looking for. To wit, you could add the following code to
features/environment.py, and it should do the trick:As a side-note, and indicated in a comment above, the normal convention in behave is for the tags for fixtures to be called
fixture.<something>. Per the docs:That said, I left the code to react to the feature file as you present it, since you state you're hoping to use the same file, presumably unchanged.