Since the scenarios are not sharing the same background, why not moving the special one to other feature files or just not using background.
But if you still want to use background section, I would recommend:
Firstly, Add a hook to your environment.py
def before_scenario(context, scenario):
if 'need_background ' in scenario.tags:
context.if_background = True
else:
context.if_background = False
Then combine all your steps in background as one step
@given('all background steps are done')
def step_impl(context):
if context.if_background:
context.context.execute_steps('''
steps in background
''')
else:
pass
Now, if your feature file is:
Feature: Background with condition
Background:
Given all background steps are done
Scenario: run without background
# steps of the scenario you don't need background
@need_background
Scenario: run with background
# steps of the scenario you need background
I think it might meet your requirements