Remove hard coded line numbers from operation tests.
@@ -441,21 +441,23 @@ class TestOperationExceptions(TestCase):
with self.assertRaises(PyinfraError) as context:
add_op(None, server.shell)
+ call_line = getframeinfo(currentframe()).lineno - 1
pyinfra.is_cli = False
assert context.exception.args[0] == (
'`add_op` should not be called when pyinfra is executing in CLI mode! '
- '(line 362 in tests/test_api/test_api_operations.py)'
+ '(line {0} in tests/test_api/test_api_operations.py)'.format(call_line)
)
def test_op_call_rejects_no_cli(self):
with self.assertRaises(PyinfraError) as context:
server.shell()
+ call_line = getframeinfo(currentframe()).lineno - 1
assert context.exception.args[0] == (
'API operation called without state/host: '
- 'server.shell (line 373 in tests/test_api/test_api_operations.py)'
+ 'server.shell (line {0} in tests/test_api/test_api_operations.py)'.format(call_line)
)
def test_op_call_rejects_in_op(self):
@@ -466,13 +468,14 @@ class TestOperationExceptions(TestCase):
with self.assertRaises(PyinfraError) as context:
server.shell()
+ call_line = getframeinfo(currentframe()).lineno - 1
pyinfra.is_cli = False
pseudo_state.reset()
assert context.exception.args[0] == (
'Nested operation called without state/host: '
- 'server.shell (line 387 in tests/test_api/test_api_operations.py)'
+ 'server.shell (line {0} in tests/test_api/test_api_operations.py)'.format(call_line)
)
def test_op_call_rejects_in_deploy(self):
@@ -484,11 +487,12 @@ class TestOperationExceptions(TestCase):
with self.assertRaises(PyinfraError) as context:
server.shell()
+ call_line = getframeinfo(currentframe()).lineno - 1
pyinfra.is_cli = False
pseudo_state.reset()
assert context.exception.args[0] == (
'Nested deploy operation called without state/host: '
- 'server.shell (line 405 in tests/test_api/test_api_operations.py)'
+ 'server.shell (line {0} in tests/test_api/test_api_operations.py)'.format(call_line)
)
