There are several possibilities:
If you have made a mistake using software and tested against an alternative in the wrong tail from what you intended, then it is best to do the correct test.
If the test in the "wrong" tail was what you really intended, then it is cheating to choose between left and right tail only after seeing the results. If you're going to use a one-tailed test you need to declare that in advance
of data collection.
If you have no idea the direction of the effect as data collection starts, then you should use a two-sided alternative. (The P-value of a 2-sided test is double the P-value of a test in the "correct" tail; changing direction of alternative after seeing (some) data is P-hacking).
Consider the following fictitious data and three t tests:
Generate fictitious data
set.seed(1234)
x = rnorm(40, 54, 6)
summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
39.93 48.50 50.96 51.52 54.49 68.50
Test $H_0: \mu=50$ vs. $H_a: \mu > 50.$
Purpose: is to see if population mean exceeds 50.
t.test(x, mu=50, alt="gr")$p.val
[1] 0.04386101 # Significant at 5% level
Test $H_0: \mu=50$ vs. $H_a: \mu < 50.$
Unexpected data? Honest blunder using R?
t.test(x, mu=50, alt="less")$p.val
[1] 0.956139 # Very large P-value
# can signal wrong tail
Test $H_0: \mu=50$ vs. $H_a: \mu \ne 50.$
Correct test if you wondered at the start whether there is a difference from 50,
with no idea in advance whether smaller or larger than 50.
t.test(x, mu=50)$p.val
[1] 0.08772203 # P-val twice the first;
# not signif at 5% level